parent
c454c6963b
commit
9cc7f84a21
@ -0,0 +1,2 @@
|
||||
docs
|
||||
frontend
|
@ -1,23 +1,17 @@
|
||||
FROM golang:1.17 as api-builder
|
||||
FROM golang:1.17 as builder
|
||||
|
||||
WORKDIR /usr/local/bin
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o dashboard .
|
||||
|
||||
FROM node:17 as web-builder
|
||||
|
||||
WORKDIR /usr/local/bin
|
||||
|
||||
RUN cd frontend && npm install && ng build --output-path web
|
||||
RUN git clone https://github.com/xpunch/go-micro-dashboard.git /usr/local/micro \
|
||||
&& cd /usr/local/micro \
|
||||
&& go install github.com/swaggo/swag/cmd/swag@latest \
|
||||
&& swag init \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o dashboard .
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /usr/local/bin
|
||||
|
||||
COPY --from=api-builder /usr/local/bin/dashboard .
|
||||
|
||||
COPY --from=web-builder /usr/local/bin/web .
|
||||
COPY --from=builder /usr/local/micro/dashboard .
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD [ "/usr/local/bin/dashboard" ]
|
||||
ENTRYPOINT [ "/usr/local/bin/dashboard" ]
|
@ -0,0 +1,83 @@
|
||||
# all folders and files are relative to the path
|
||||
# where fileb0x was run at!
|
||||
|
||||
# default: main
|
||||
pkg: web
|
||||
|
||||
# destination
|
||||
dest: "./web/"
|
||||
|
||||
# gofmt
|
||||
# type: bool
|
||||
# default: false
|
||||
fmt: true
|
||||
|
||||
# compress files
|
||||
# at the moment, only supports gzip
|
||||
#
|
||||
# type: object
|
||||
compression:
|
||||
# activates the compression
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
compress: false
|
||||
|
||||
# valid values are:
|
||||
# -> "NoCompression"
|
||||
# -> "BestSpeed"
|
||||
# -> "BestCompression"
|
||||
# -> "DefaultCompression" or ""
|
||||
#
|
||||
# type: string
|
||||
# default: "DefaultCompression" # when: Compress == true && Method == ""
|
||||
method: ""
|
||||
|
||||
# true = do it yourself (the file is written as gzip compressed file into the memory file system)
|
||||
# false = decompress files at run time (while writing file into memory file system)
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
keep: false
|
||||
|
||||
# ---------------
|
||||
# -- DANGEROUS --
|
||||
# ---------------
|
||||
#
|
||||
# cleans the destination folder (only b0xfiles)
|
||||
# you should use this when using the spread function
|
||||
# type: bool
|
||||
# default: false
|
||||
clean: true
|
||||
|
||||
# default: ab0x.go
|
||||
output: "ab0x.go"
|
||||
|
||||
# [unexporTed] builds non-exporTed functions, variables and types...
|
||||
# type: bool
|
||||
# default: false
|
||||
unexporTed: false
|
||||
|
||||
# [spread] means it will make a file to hold all fileb0x data
|
||||
# and each file into a separaTed .go file
|
||||
#
|
||||
# example:
|
||||
# theres 2 files in the folder assets, they're: hello.json and world.txt
|
||||
# when spread is activaTed, fileb0x will make a file:
|
||||
# b0x.go or [output]'s data, assets_hello.json.go and assets_world.txt.go
|
||||
#
|
||||
#
|
||||
# type: bool
|
||||
# default: false
|
||||
spread: true
|
||||
|
||||
# [lcf] log changed files when spread is active
|
||||
lcf: true
|
||||
|
||||
# type: array of objects
|
||||
custom:
|
||||
- files:
|
||||
- "frontend/dist"
|
||||
base: "frontend/dist"
|
||||
exclude:
|
||||
- "/3rdpartylicenses.txt"
|
@ -1,11 +0,0 @@
|
||||
server:
|
||||
env: "dev"
|
||||
address: ":4000"
|
||||
cors:
|
||||
enable: true
|
||||
origin: "http://localhost:4200"
|
||||
swagger:
|
||||
host: "localhost:4000"
|
||||
base: "/"
|
||||
web:
|
||||
path: "./web"
|
@ -0,0 +1,144 @@
|
||||
// Code generated by fileb0x at "2021-11-22 15:58:09.6945407 +0800 CST m=+0.053806901" from config file "b0x.yaml" DO NOT EDIT.
|
||||
// modification hash(40921e3ce04e6483775714327fee4445.8be3f833d63e3c844663716446e13a42)
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"golang.org/x/net/webdav"
|
||||
)
|
||||
|
||||
var (
|
||||
// CTX is a context for webdav vfs
|
||||
CTX = context.Background()
|
||||
|
||||
// FS is a virtual memory file system
|
||||
FS = webdav.NewMemFS()
|
||||
|
||||
// Handler is used to server files through a http handler
|
||||
Handler *webdav.Handler
|
||||
|
||||
// HTTP is the http file system
|
||||
HTTP http.FileSystem = new(HTTPFS)
|
||||
)
|
||||
|
||||
// HTTPFS implements http.FileSystem
|
||||
type HTTPFS struct {
|
||||
// Prefix allows to limit the path of all requests. F.e. a prefix "css" would allow only calls to /css/*
|
||||
Prefix string
|
||||
}
|
||||
|
||||
func init() {
|
||||
err := CTX.Err()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = FS.Mkdir(CTX, "/assets/", 0777)
|
||||
if err != nil && err != os.ErrExist {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Handler = &webdav.Handler{
|
||||
FileSystem: FS,
|
||||
LockSystem: webdav.NewMemLS(),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Open a file
|
||||
func (hfs *HTTPFS) Open(path string) (http.File, error) {
|
||||
path = hfs.Prefix + path
|
||||
|
||||
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// ReadFile is adapTed from ioutil
|
||||
func ReadFile(path string) ([]byte, error) {
|
||||
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(make([]byte, 0, bytes.MinRead))
|
||||
|
||||
// If the buffer overflows, we will get bytes.ErrTooLarge.
|
||||
// Return that as an error. Any other panic remains.
|
||||
defer func() {
|
||||
e := recover()
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
|
||||
err = panicErr
|
||||
} else {
|
||||
panic(e)
|
||||
}
|
||||
}()
|
||||
_, err = buf.ReadFrom(f)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
// WriteFile is adapTed from ioutil
|
||||
func WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||
f, err := FS.OpenFile(CTX, filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := f.Write(data)
|
||||
if err == nil && n < len(data) {
|
||||
err = io.ErrShortWrite
|
||||
}
|
||||
if err1 := f.Close(); err == nil {
|
||||
err = err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// WalkDirs looks for files in the given dir and returns a list of files in it
|
||||
// usage for all files in the b0x: WalkDirs("", false)
|
||||
func WalkDirs(name string, includeDirsInList bool, files ...string) ([]string, error) {
|
||||
f, err := FS.OpenFile(CTX, name, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileInfos, err := f.Readdir(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range fileInfos {
|
||||
filename := path.Join(name, info.Name())
|
||||
|
||||
if includeDirsInList || !info.IsDir() {
|
||||
files = append(files, filename)
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
files, err = WalkDirs(filename, includeDirsInList, files...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,50 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoute(router *gin.Engine) error {
|
||||
files, err := WalkDirs("", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
router.GET(f, func(name string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
data, err := ReadFile(name)
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
switch filepath.Ext(name) {
|
||||
case ".html":
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
case ".css":
|
||||
c.Header("Content-Type", "text/css; charset=utf-8")
|
||||
case ".js":
|
||||
c.Header("Content-Type", "application/javascript")
|
||||
}
|
||||
if _, err := c.Writer.Write(data); err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}(f))
|
||||
}
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
data, err := ReadFile("index.html")
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
if _, err := c.Writer.Write(data); err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
})
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue