Giter VIP home page Giter VIP logo

go-html-boilerplate's Introduction

Go html boilerplate

This is a starter pack for doing web development with Go, with support for some of the things you'll usually want to add to an HTML web server:

  • Adding templates and rendering them
  • Regex matching for routes
  • Logging requests and responses
  • Serving static content with caching/busting
  • Watching/restarting the server after changes to CSS/templates
  • Loading configuration from a config file
  • Flash success and error messages

Read more about the choices and the feature set found here. You can see an example project using go-html-boilerplate here.

Feel free to adapt the project as you see fit; that should be pretty easy to do since no one component does too much on its own, and all of them operate on standard library interfaces like http.Handler.

To get started, run go get ./... and then make serve to start a server on port 7065. You may need to run make generate_cert to generate a self-signed certificate for local use.

Templates go in the "templates" folder; you can see how they're loaded by examining the init function in main.go. Run make assets to recompile them into the binary.

Static files go in the "static" folder. Run make assets to recompile them into the binary.

Watching for changes

Run make watch to restart the server after you make changes to the assets directory.

If you are on a Mac, be sure to add this folder to the Spotlight privacy list, or file modify events will fire a second time when Spotlight indexes updates.

go-html-boilerplate's People

Contributors

kevinburke avatar

Watchers

 avatar  avatar

go-html-boilerplate's Issues

be smarter about Make targets

Right now we run make assets serve but there's no need to run make assets if none of the mtimes on the assets are updated.

The assets target should specify all of the files it depends on, then it can check the mtimes on those to figure out whether it needs to recompile.

Same for go install, we can skip it if none of the files changed.

Consider using vfsgen for accessing/embedding resources.

Hey Kevin,

I suspect there's a good chance this project could be simplified, while still doing everything it's doing now, and more (like applying HTTP gzip compression of embedded static resources efficiently), by using vfsgen. Instead of go-bindata as it currently does.

Have you already considered vfsgen? Are you interested in exploring this direction?

I've created a similar but simpler project for getting started with GopherJS at https://github.com/gopherjs/gopherpen, which might be worth looking at as an example.

Let me know what you think, either way. Thanks for consideration!

Rendering templates with a header and footer

If you have more than one template, you probably want them to share a header and a footer. Unfortunately that's not trivial to set up.

It would be nice to have an example showing how to do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.