/
main.go
53 lines (45 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
//go:generate cp node_modules/marked/lib/marked.js _assets/
//go:generate cp node_modules/jquery/dist/jquery.min.js _assets/
//go:generate go-bindata $GOBINDATAARGS data/... _assets/...
import (
"fmt"
"os"
static "github.com/Code-Hex/echo-static"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
var (
// SavePath ...
SavePath string
)
// NewAssets ...
func NewAssets(root string) *assetfs.AssetFS {
return &assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
Prefix: root,
}
}
func initSavePath(savePath string) error {
SavePath = savePath
return os.MkdirAll(SavePath, 0777)
}
func main() {
c := parseArgs()
err := initSavePath(c.storePath)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
e := echo.New()
e.Use(middleware.Logger())
e.Use(static.ServeRoot("/_assets", NewAssets("_assets")))
e.Use(static.ServeRoot("/node_modules", NewAssets("node_modules")))
e.GET("/", getRoot)
e.GET("/api/markdown", getMarkdown)
e.POST("/api/markdown", postMarkdown)
e.Logger.Fatal(e.Start(":" + c.port))
}