From 7e89c0795152bed4aaa18d2c46db803200a743af Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 16 Dec 2021 19:44:07 +0800 Subject: [PATCH] save --- Makefile | 2 +- README.md | 8 +++++++- main.go => cmd/test/main.go | 0 history/history.go | 10 ++++++++++ run.sh | 9 +++++++++ system/setup.go | 22 +++++++++++++++++++--- 6 files changed, 46 insertions(+), 5 deletions(-) rename main.go => cmd/test/main.go (100%) create mode 100644 run.sh diff --git a/Makefile b/Makefile index 330dc96..054ab4f 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,4 @@ run: APP_LOG_PRETTY=true \ APP_DB_TYPE=sqlite \ APP_DATA=work \ - go run main.go \ No newline at end of file + go run cmd/test/main.go \ No newline at end of file diff --git a/README.md b/README.md index b126c23..dd63f95 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Kumoly App -combine all needed module into one lib \ No newline at end of file +combine all needed module into one lib + +## Run + +``` + +``` \ No newline at end of file diff --git a/main.go b/cmd/test/main.go similarity index 100% rename from main.go rename to cmd/test/main.go diff --git a/history/history.go b/history/history.go index e25ce63..0819c2e 100644 --- a/history/history.go +++ b/history/history.go @@ -3,6 +3,8 @@ package history import ( "fmt" "time" + + "kumoly.io/kumoly/app/errors" ) const ( @@ -26,19 +28,27 @@ type History struct { var Tunnel chan *History var quit chan struct{} +var started chan struct{} func init() { Tunnel = make(chan *History) quit = make(chan struct{}, 1) + started = make(chan struct{}, 1) } func Start(r Receiver) { + select { + case started <- struct{}{}: + default: + panic(errors.New(500, "history has already started!")) + } go func() { for { select { case h := <-Tunnel: r(h) case <-quit: + <-started return } } diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..e8149a4 --- /dev/null +++ b/run.sh @@ -0,0 +1,9 @@ + +export APP_SERVER_HOST=127.0.0.1 +export APP_SERVER_PORT=8000 +export APP_LOG_LEVEL=-1 +export APP_PROD=false +export APP_LOG_PRETTY=true +export APP_DB_TYPE=sqlite +export APP_DATA=work +go run cmd/test/main.go \ No newline at end of file diff --git a/system/setup.go b/system/setup.go index e2d099f..0aabf29 100644 --- a/system/setup.go +++ b/system/setup.go @@ -1,6 +1,7 @@ package system import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -61,9 +62,24 @@ func setup() { if cc, ok := i.(string); ok { c = cc } - // if len(c) > 0 { - - // } + if len(c) > 0 { + // shorten caller to mod/file:line + segs := strings.Split(c, ":") + file := segs[len(segs)-2] + short := file + skip := false + for i := len(file) - 1; i > 0; i-- { + if file[i] == '/' { + if !skip { + skip = true + continue + } + short = file[i+1:] + break + } + } + return fmt.Sprintf("%v:%v", short, segs[len(segs)-1]) + } return c }, })