add flag options, add schema submodule

This commit is contained in:
Jay 2018-09-19 20:23:39 +08:00
parent e86171151a
commit a43bf98e21
7 changed files with 71 additions and 2 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "schema"]
path = schema
url = https://git.trj.tw/mtfos/mtfosbot_schema

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM golang:1.11-alpine3.8 as builder
WORKDIR /go/src/git.trj.tw/golang/mtfosbot
COPY . .
RUN GOOS=linux go build -o mtfosbot .
FROM alpine:latest
RUN apk add --no-cache ca-certificates
WORKDIR /data
COPY --from=builder /go/src/git.trj.tw/golang/mtfosbot/mtfosbot /usr/bin
COPY config.default.yml config.yml
EXPOSE 10230
CMD ["/usr/bin/mtfosbot", "-f", "/data/config.yml", "-dbtool"]

16
main.go
View File

@ -3,12 +3,14 @@ package main
import (
"encoding/gob"
"errors"
"flag"
"log"
"os"
"path"
"strconv"
"strings"
"git.trj.tw/golang/mtfosbot/module/options"
"git.trj.tw/golang/mtfosbot/module/utils"
"git.trj.tw/golang/mtfosbot/model"
@ -21,8 +23,20 @@ import (
var server *gin.Engine
func init() {
options.RegFlag()
flag.Parse()
}
func main() {
err := config.LoadConfig()
runOptions := options.GetFlag()
if runOptions.Help {
flag.Usage()
return
}
err := config.LoadConfig(runOptions.Config)
if err != nil {
log.Fatal(err)
}

6
module/cmd/cmd.go Normal file
View File

@ -0,0 +1,6 @@
package cmd
// DBTool - deploy database schemas
func DBTool() {
}

28
module/options/options.go Normal file
View File

@ -0,0 +1,28 @@
package options
import (
"flag"
)
// Options - flag options
type Options struct {
Help bool
Config string
DBTool bool
}
var opts *Options
// RegFlag - register flag
func RegFlag() {
opts = &Options{}
flag.StringVar(&opts.Config, "config", "", "config file path (defualt {PWD}/config.yml")
flag.StringVar(&opts.Config, "f", "", "config file path (short) (defualt {PWD}/config.yml")
flag.BoolVar(&opts.DBTool, "dbtool", false, "run dbtool deploy schema")
flag.BoolVar(&opts.Help, "help", false, "show help")
}
// GetFlag -
func GetFlag() *Options {
return opts
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"git.trj.tw/golang/mtfosbot/module/config"
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/router/api"
"git.trj.tw/golang/mtfosbot/router/google"
@ -19,7 +20,11 @@ import (
func NewServ() *gin.Engine {
r := gin.New()
store, err := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("seckey"))
conf := config.GetConf()
redisStr := fmt.Sprintf("%s:%d", conf.Redis.Host, conf.Redis.Port)
store, err := sessions.NewRedisStore(10, "tcp", redisStr, "", []byte("seckey"))
if err != nil {
log.Fatal(err)
}

1
schema Submodule

@ -0,0 +1 @@
Subproject commit 33f8a1dc6ea0de9323e9a75f5366fa68d8325774