Serve Vuejs ด้วย Golang


Require

- github.com/labstack/echo/v4 # framework api golang
- vuejs

Frontend (vuejs)

  • Create
$ vue create frontend
$ cd frontend
  • Edit Yarn build
  "scripts": {
    ...
    "build": "vue-cli-service build --dest ../views",
    ...
  },
  • build
$ yarn build

Golang

  • Mod Init
$ go mod init <project>
  • Import library
import (
    "github.com/labstack/echo/v4"
)
  • Function Main
func main() {
    e := echo.New()
    e.Use(middleware.Static("views"))
    e.File("*", "views/index.html")
    e.Logger.Fatal(e.Start(":9000"))
}
  • All
package main

import (
    "github.com/labstack/echo/v4"
)

func main() {
    e := echo.New()
    e.Use(middleware.Static("views"))
    e.File("*", "views/index.html")
    e.Logger.Fatal(e.Start(":9000"))
}
  • Run
$ go run .


  • Source

GitHub - jaedsadadotme/go-vue

August 15, 2020