7 ms·
Show HN: Copper – A Go framework for your projects
Hey HN! I've been working with Go for the last 5+ years at large-ish companies building products that many of you may use regularly.
A ton of people say that Go's standard library is really powerful and usually enough to get by without external dependencies. I think that's true for companies that have the resources to build and maintain packages to reduce code duplication. For everyone else, we're left to finding the right set of packages to build our projects.
So, I built Copper - a toolkit that helps you get your project off the ground with minimal dependencies. It covers everything from routing, html, storage to tooling and more.
Check it out, star it, and feel free to ask questions!
P.S.
I also have a video demo building an HN clone in the docs
[1] https://gocopper.dev/ https://gocopper.dev/
- synergy20 4y agoSo go is trying to be a server-side-render framework here, what about the SPA style in that go is a simple json-api server, and let SPA to do all the template and render, is gin the best framework for that? new to golang here.
- dangelov 4y agoI've been using Mux & sqlc in a few projects and it's working out great.
- synergy20 4y agoboth look interesting, "Mux is looking for new Maintainers"
- AlphaSite 4y agoI found Echo a better framework than gin, since it cleans up some of the warts around error handling etc. As for database, jet is my favourite thus far.
- tusharsoni 4y agoI think that remains a very valid use case. In Copper, you can create one of those with the CLI. For example `copper create -frontend=vite:react github.com/nasa/starship` will create a react app with a JSON backed API ready to go
- deleted 4y ago[deleted]
- jjtheblunt 4y agoDoesn't the Go standard library do what you mentioned above?
- tusharsoni 4y agoIt kinda does but there's a lot of boilerplate that goes in before we actually get to the app logic. And, understandably, there's no structure provided by the Go stdlib. Once I made many projects with just using stdlib, I started taking common packages out. And Copper is essentially that. I can start writing my app code with minimal setup / boilerplate.
- atwood22 4y agoGo’s HTTP routing is very primitive. That’s one big area that I’ve always needed to use a 3rd party dependency. The main issue is that it doesn’t support placeholder values in route paths.
- telesoft 4y ago>The main issue is that it doesn’t support placeholder values Can you elaborate? Like give me an example of a route path that uses placeholder values? I use Go to build web apps too and I really don't see a need for anything other than the standard library.
- evilthrow 4y agoGET /{username}
- telesoft 4y agoYou definitely don't need a framework to get the user name out of a URL, you need one line of code.
- evilthrow 4y agoAnd what would that line of code be? As far as I am aware you have to parse the URL string, and it only gets more complicated when you add more URL parameters. Which definitely leads to boilerplate code shared across projects.
- ge96 4y agoI saw on the "who's hiring" for July Go is at the same level of demand as Node pretty cool Gotta put Go on my list of things to learn
- tusharsoni 4y agoPlease do! If nothing else, it's definitely a fun language to learn. We're also setting up a community of folks who are learning Go/Copper. Check the project readme link for the link.
- lokeshchoudhary 4y ago
- mstef9 4y agoDevs interested in this may also be interested in Pagoda [1], a rapid, easy full-stack web development starter kit in Go that I wrote. It leverages popular frameworks and modules that you can easily swap out, if desired. The readme contains full documentation and it's very much batteries-included. [1] https://github.com/mikestefanello/pagoda https://github.com/mikestefanello/pagoda
- hdra 4y agojust wanted to say i really like the approach of a "template/starter" that you took. My team isn't starting a new project anytime soon to really make full use of it, but we have pretty much adopted the pagoda service container approach in our home-grown "framework".
- telesoft 4y agoCool project. I'm currently building something similar to hacker news using only the standard library. How could this project help me? The way I use the standard library is like a super condensed version of React. Templates are my components. Since templates can be nested, templates can be used to build "components" and those components can be stored in separate files and compiled together at run time with a "model" being fed to the template(s) via a state object passed by the application. So I may have a few dozen template files in a folder called /components, and another folder called /pages with a few templates that use these components. When a user visits a "page", the template file is "compiled" with the appropriate components. A page might look like this: <html> {{template "nav"}} {{template "thread" .Thread}} {{template "footer"}} </html> And "nav", "thread", and "footer" are all components defined in another file. This allows for re-use across multiple pages. I want to do a write-up on it but I'm not sure if it's a novel idea.
- skinnyarms 4y agoSounds like old school server-side rendering techniques to me: php, coldfusion, classic ASP
- pram 4y agoYou didn't even need a language, plain old shtml in Apache could do SSI from static includes. Classic.
- tusharsoni 4y agoOh that's fun! In my demo video [1], I build a (minimal) HN clone so hopefully that answers your question in detail. But the tldr is - you'll need a lot more than just templating for a production ready app. To name a few things - server, storage, migrations, logging, configs. IMO there's a huge benefit in having a batteries included toolkit that stays close to the stdlib - so you can totally keep your templates as is! [1] https://vimeo.com/723537998 https://vimeo.com/723537998
- morelisp 4y agoIn what sense is this like React? Incremental re-rendering using html/template or text/template was virtually impossible last time I looked into it (for improving performance of some report generation), let alone getting any kind of DOM tree structure out.
- theplumber 4y agoAm I do only one who hates frameworks that need a cli to get started?
- tusharsoni 4y agoha, add me to that list :) I think it's fine if CLIs are optional and I've tried to do that with Copper. Of course, your initial setup will be longer without scaffolding so it's not a great first time developer experience
- EToS 4y agoMe too, although if its a lightweight helper you can ditch down the line its normally not an issue
- born-jre 4y agothis looks fine but not a fan of gorm. but it could be decent choice if u want to build integrated framework i can understand why people would choose it, another option is code_generation_meta_hell with sqlboiler. upper db [0] would have been perfect fit for this kind of project but is not that famous, its development is slow but stable. ps: i like sqlboiler what i am saying is if u are building framework top on it then not that fun [0]: https://github.com/upper/db https://github.com/upper/db edit: include link
- tusharsoni 4y agoCode generation is an awesome alternate, I'm more familiar with sqlc.dev. They're doing some really interesting work. My goal with Copper is to provide out-of-the-box integrations with popular solutions to various problems. For now, I picked GORM but I definitely see adding support for other tools.
- swagonomixxx 4y agoWill 2nd not being a fan of Gorm. In general not a fan of ORMs - implicit behaviours and magic query generation in a language like Go is completely antithetical to the explicit and verbose nature of the language.
- mstef9 4y agowhat do you think of Ent [1]? [1] https://entgo.io/ https://entgo.io/
- zinodaur 4y agoCopper looks really cool - bringing the rapid dev of Rails to golang. Very tight demo btw
- icod1 4y ago[flagged]
- digitalsin 4y agoShow me on the dolly where the mean framework hurt you.
- dang 4y ago"Don't feed egregious comments by replying; flag them instead." a.k.a. please don't feed the trolls https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- digitalsin 4y agoYou're right, apologies.
- dang 4y agoYour seriously broke both the Show HN guidelines and the site guidelines with your post here. https://news.ycombinator.com/showhn.html https://news.ycombinator.com/showhn.html https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html We ban accounts that break the rules like this. If you wouldn't mind reviewing them and sticking to them in the future, we'd appreciate it.
- bestinterest 4y agoSo many frameworks in other languages are trying to get to the productivity of Rails but they just don't have the same spark imo. There is no Rails equivalent in JS, theres lots of competitors that feel years away like SailsJS, the new Deno Fresh one etc, Adonisjs... Is NextJS/SvelteKit/RemixRun considered also? I don't even know if they have a standardised background job processor in JS land. Java's solutions are dreadful imo for if you want to compare to Rails. Quarkus/SpringBoot/Micronaut are nowhere near productivity levels for a fullstack app. They lean heavily on the API only side of things. (I do like Java oddly enough) PHP is the main competitor to Rails oddly enough, Laravel seems brilliant. Go is just starting up in this space it looks like, Bud is another attempt at Rails in another language https://github.com/livebud/bud https://github.com/livebud/bud. However the Go ecosystem is heavily API only side of things instead of SSR. Go's templating libs suck imo. Elixir of course has Phoneix which is apparently great, purely functional langs unfortunately dont fit my head and feel to abstract for myself (don't hate me) Its no wonder we have the backend / frontend developer split nowadays.
- tusharsoni 4y agoThis is a good observation. One trend I'm noticing is that the "old way" (PHP, Rails, etc.) of doing things is making a comeback. Go is very well positioned for this but lacks the frameworks. I'm hoping to add something like Phoenix to Copper. It should help with the "heavily API only side" problem. I've already added integrations for Tailwind and added some utilities on top of the templating (going to add more) to fix the lack of good templating.
- melony 4y agoGo and Java can never use the same framework patterns as Python/Php/Elixir/Ruby/JS because they are not dynamic enough. The Rails-style request mapped dispatching into active record ORM pattern requires a lot of flexibility on the host language side. For Go and Java, you basically end up with code generation or reflection, and the latter is a killer for performance. On the other hand, the performance of Go and Java is better by several orders of magnitude.
- pram 4y agoHaha, moscow mule? I appreciate the alcohol name theme to go with all the other Go web frameworks. ;P
- tusharsoni 4y agohaha yeah, gotta keep the tradition going
- deleted 4y ago[deleted]
- matthewmueller 4y agoAuthor of https://github.com/livebud/bud https://github.com/livebud/bud here, congrats on the launch Tushar! Looking forward to building up the Go web framework ecosystem with you!
- tusharsoni 4y agoThank you, so much to do in this space! Bud looks great and I see we share many common goals. The dependency injection piece looks interesting. Did you build it custom or integrated an existing solution?
- andreygrehov 4y agoCongrats! > One Binary > Build frontend apps along with your backend and ship everything in a single binary. I'm doing something similar and love it. Do you embed the entire `public` directory and then traverse the embed.FS to access the files in memory?
- leetrout 4y agoThat is how I am building mine and have thoroughly enjoyed it. Especially since 1.18 updated support to allow directories / files that start with an underscore. I am using svelte for the frontend and that was biting me.
- capableweb 4y ago> I'm doing something similar and love it. Do you embed the entire `public` directory and then traverse the embed.FS to access the files in memory? I've done this in Rust before, I'm sharing it here as I'm assuming that Go has something similar. I'm basically hard-coding the paths in the backend to also serve static assets, and embed the bytes of the asset at compile time, so when it runs, it's just serving it straight from memory. Here how it looks for style.css for example: https://codeberg.org/ditzes/ditzes/src/branch/master/src-tauri/src/api.rs#L326 https://codeberg.org/ditzes/ditzes/src/branch/master/src-tau... It'd be trivial to move the structure to something like a map instead, where the URL is the key and another map where bytes, headers and such is stored. Mostly I didn't, because I'm just embedding few amount of files.
- tusharsoni 4y agoThank you! Go supports embedding static files natively [1]. Copper builds on top of it and provides the tooling to do it seamlessly for web projects. [1]: https://pkg.go.dev/embed https://pkg.go.dev/embed
- binwiederhier 4y agoembed.FS is really cool. If you wanna see what it looks like, check out how I build ntfy [0]. It ships with the docs (built from mkdocs, see [1]) and the React web app [2] all in a single binary. Here are the embed statements [3]. One thing to note is that embed.FS does not send 304 Not Modified status back, which is why I made a CachingEmbedFS [4]. [0] https://github.com/binwiederhier/ntfy/blob/main/Makefile#L77 https://github.com/binwiederhier/ntfy/blob/main/Makefile#L77 [1] https://ntfy.sh/docs/ https://ntfy.sh/docs/ [2] https://ntfy.sh/app https://ntfy.sh/app [3] https://github.com/binwiederhier/ntfy/blob/main/server/server.go#L79-L88 https://github.com/binwiederhier/ntfy/blob/main/server/serve... [4] https://github.com/binwiederhier/ntfy/blob/main/util/embedfs.go https://github.com/binwiederhier/ntfy/blob/main/util/embedfs...
- irq-1 4y agowire.go should have been named patina.go
- thiht 4y agoToo bad it uses Wire. There’s absolutely no need for dependency injection frameworks in Go, you can just inject directly to receiver functions. It does the same thing without the crappy indirection added by this kind of frameworks.
- al_mandi 4y agoHow would you compare what you wrote with what Uber built (gofx, glue, etc?)
- icod1 4y agoReading through the comments, most of you are either new to Go or new to web dev in general. Only that would explain how this SHITSHOW of a "framework" would get any praise at all. What he copy/pasted already exists, only better. The HN audience doesn't seem very sophisticaed. Hell even reddit's /r/golang is better informed than HN in this regard. Just read through all the issues people have with gorm and if you've ever did any real Go development you would not pick gorm as the default database package in the first place. Amateurs all of you, I'm seriously sick of your unprofessional lack of knowledge and experience. HackerNews my ass, more like NoobNews. GTFO