save
							parent
							
								
									905e1779a5
								
							
						
					
					
						commit
						7e89c07951
					
				
							
								
								
									
										2
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										2
									
								
								Makefile
								
								
								
								
							| 
						 | 
					@ -5,4 +5,4 @@ run:
 | 
				
			||||||
	APP_LOG_PRETTY=true \
 | 
						APP_LOG_PRETTY=true \
 | 
				
			||||||
	APP_DB_TYPE=sqlite \
 | 
						APP_DB_TYPE=sqlite \
 | 
				
			||||||
	APP_DATA=work \
 | 
						APP_DATA=work \
 | 
				
			||||||
	go run main.go
 | 
						go run cmd/test/main.go
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,9 @@
 | 
				
			||||||
# Kumoly App
 | 
					# Kumoly App
 | 
				
			||||||
 | 
					
 | 
				
			||||||
combine all needed module into one lib
 | 
					combine all needed module into one lib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Run
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,8 @@ package history
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"kumoly.io/kumoly/app/errors"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
| 
						 | 
					@ -26,19 +28,27 @@ type History struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Tunnel chan *History
 | 
					var Tunnel chan *History
 | 
				
			||||||
var quit chan struct{}
 | 
					var quit chan struct{}
 | 
				
			||||||
 | 
					var started chan struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	Tunnel = make(chan *History)
 | 
						Tunnel = make(chan *History)
 | 
				
			||||||
	quit = make(chan struct{}, 1)
 | 
						quit = make(chan struct{}, 1)
 | 
				
			||||||
 | 
						started = make(chan struct{}, 1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Start(r Receiver) {
 | 
					func Start(r Receiver) {
 | 
				
			||||||
 | 
						select {
 | 
				
			||||||
 | 
						case started <- struct{}{}:
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							panic(errors.New(500, "history has already started!"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
			select {
 | 
								select {
 | 
				
			||||||
			case h := <-Tunnel:
 | 
								case h := <-Tunnel:
 | 
				
			||||||
				r(h)
 | 
									r(h)
 | 
				
			||||||
			case <-quit:
 | 
								case <-quit:
 | 
				
			||||||
 | 
									<-started
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
package system
 | 
					package system
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
| 
						 | 
					@ -61,9 +62,24 @@ func setup() {
 | 
				
			||||||
				if cc, ok := i.(string); ok {
 | 
									if cc, ok := i.(string); ok {
 | 
				
			||||||
					c = cc
 | 
										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
 | 
									return c
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue