Skip to content

Instantly share code, notes, and snippets.

@esslamben
Last active March 23, 2019 19:47
Show Gist options
  • Save esslamben/c4835b2e4999189773f00a35865ecb35 to your computer and use it in GitHub Desktop.
Save esslamben/c4835b2e4999189773f00a35865ecb35 to your computer and use it in GitHub Desktop.
main.go
package main
import (
"net/http"
rice "github.com/GeertJohan/go.rice"
"github.com/labstack/echo"
)
func main() {
// Create new instance of echo
e := echo.New()
// Setup our assetHandler and point it to our static build location
assetHandler := http.FileServer(rice.MustFindBox("../../web/golang-react/build").HTTPBox())
// Setup a new echo route to load the build as our base path
e.GET("/", echo.WrapHandler(assetHandler))
// Serve our static assists under the /static/ endpoint
e.GET("/static/*", echo.WrapHandler(assetHandler))
// Test API route
e.GET("/api/test", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
// Start echo instance on 1323 port
e.Logger.Fatal(e.Start(":1323"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment