1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

ref: embed files, bump to go 1.16 (#167)

* ref: embed portion of files
* fix: readd pkger
* ref: embed version.txt
* fix: wrong mail template import path
* refactor: get rid of sql-migrate
refactor: get rid of pkger in favor of go embed (resolve #164)
* chore: remove unused var [ci-skip]

Co-authored-by: Ferdinand Mütsch <ferdinand@muetsch.io>
This commit is contained in:
Steven Tang
2021-04-11 10:42:43 +00:00
committed by GitHub
parent 2a9fbfdfd7
commit 6256c8e10a
18 changed files with 136 additions and 448 deletions

30
main.go
View File

@@ -1,11 +1,16 @@
package main
//go:generate $GOPATH/bin/pkger
import (
"embed"
"io/fs"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/emvi/logbuch"
"github.com/gorilla/handlers"
"github.com/markbates/pkger"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/migrations"
"github.com/muety/wakapi/repositories"
@@ -13,11 +18,6 @@ import (
"github.com/muety/wakapi/services/mail"
"github.com/muety/wakapi/utils"
"gorm.io/gorm/logger"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/gorilla/mux"
"github.com/muety/wakapi/middlewares"
@@ -31,6 +31,14 @@ import (
"gorm.io/gorm"
)
// Embed version.txt
//go:embed version.txt
var version string
// Embed static files
//go:embed static
var staticFiles embed.FS
var (
db *gorm.DB
config *conf.Config
@@ -80,7 +88,7 @@ var (
// @BasePath /api
func main() {
config = conf.Load()
config = conf.Load(version)
// Set log level
if config.IsDev() {
@@ -196,7 +204,9 @@ func main() {
shieldV1BadgeHandler.RegisterRoutes(apiRouter)
// Static Routes
fileServer := http.FileServer(utils.NeuteredFileSystem{Fs: pkger.Dir("/static")})
// https://github.com/golang/go/issues/43431
static, _ := fs.Sub(staticFiles, "static")
fileServer := http.FileServer(utils.NeuteredFileSystem{Fs: http.FS(static)})
router.PathPrefix("/assets").Handler(fileServer)
router.PathPrefix("/swagger-ui").Handler(fileServer)
router.PathPrefix("/docs").Handler(