github.com/ppphp/yayagf@v0.0.1/README.md (about) 1 2 [![pipeline status](https://github.com/ppphp/yayagf/badges/master/pipeline.svg)](https://github.com/ppphp/yayagf/commits/master) 3 [![coverage report](https://github.com/ppphp/yayagf/badges/master/coverage.svg)](https://github.com/ppphp/yayagf/commits/master) 4 [![SQALE评级](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=sqale_rating)](http://192.168.0.97:9000/dashboard?id=yayagf) 5 # yayagf 6 7 yet another yet another go web framework, my practice 8 9 it is a 缝合怪 of some tool 10 - http: gin-gonic/gin 11 - monitor: prometheus/client_golang 12 - database: facebook/ent 13 - cli: alecthomas/kingpin (WIP) 14 15 ###### sonar 16 [![Bugs](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=bugs)](http://192.168.0.97:9000/dashboard?id=yayagf) 17 [![异味](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=code_smells)](http://192.168.0.97:9000/dashboard?id=yayagf) 18 [![覆盖率](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=coverage)](http://192.168.0.97:9000/dashboard?id=yayagf) 19 [![重复行(%)](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=duplicated_lines_density)](http://192.168.0.97:9000/dashboard?id=yayagf) 20 [![代码行数](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=ncloc)](http://192.168.0.97:9000/dashboard?id=yayagf) 21 [![警报](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=alert_status)](http://192.168.0.97:9000/dashboard?id=yayagf) 22 [![可靠性比率](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=reliability_rating)](http://192.168.0.97:9000/dashboard?id=yayagf) 23 [![安全比率](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=security_rating)](http://192.168.0.97:9000/dashboard?id=yayagf) 24 [![技术债务](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=sqale_index)](http://192.168.0.97:9000/dashboard?id=yayagf) 25 [![漏洞](http://192.168.0.97:9000/api/project_badges/measure?project=yayagf&metric=vulnerabilities)](http://192.168.0.97:9000/dashboard?id=yayagf) 26 27 28 ## install 29 30 `go install ./cmd/yayagf` 31 32 ## start a project 33 34 type `yayagf new gitlab.papegames.com/fengche/abc` will generate a folder named abc 35 36 a project structure is like this 37 38 project_root 39 -app 40 --controller 41 --crud 42 --schema 43 --serializer // TODO 44 --doc 45 -config_file1 // TODO 46 -config_file2 // TODO 47 -project_root.yml // TODO 48 -Dockerfile 49 50 ## run a project 51 52 `yayagf server` will monitor the code, recompile the code when compilable and run. 53 54 ## generate a component scaffold 55 56 ```bash 57 yayagf g commands 58 yayagf generate commands 59 ``` 60 61 #### schema (ent) 62 63 will generate schema(table) in `app/schema` 64 65 ```bash 66 yayagf g schema a 67 ``` 68 69 #### crud (ent) 70 71 will generate crud files in `app/crud` according to `app/schema` 72 73 ```bash 74 yayagf g curd 75 yayagf g crud 76 ``` 77 78 #### doc (swagger) 79 80 will generate doc files in `app/doc` according to `app/controllers` 81 82 ```bash 83 yayagf g doc 84 ``` 85 86 87 #### router // TODO 88 89 #### serializer // TODO 90 91 ## write codes 92 93 ### ent (db) 94 - driver 95 ```go 96 package main 97 import ( 98 "github.com/ppphp/yayagf/pkg/model" 99 "log" 100 "yourproject/ent" 101 ) 102 103 func main() { 104 drv, err := model.Open("mysql", DBURL) 105 if err != nil { 106 log.Fatal(drv) 107 } 108 client := ent.NewClient(ent.Driver(drv)) 109 if err := client.Schema.Create(context.Background()); err != nil { 110 log.Fatal(err) 111 } 112 } 113 ``` 114 - sharding name 115 - sharding databases 116 - monitoring 117 118 119 ### config loader 120 121 ```go 122 package main 123 import ( 124 "github.com/ppphp/yayagf/pkg/config" 125 "log" 126 ) 127 128 func main() { 129 var conf struct { 130 A int 131 B string 132 } 133 config.LoadConfig(&conf) 134 log.Println(conf) 135 } 136 ``` 137 138 ### util handlers 139 ```go 140 package main 141 import ( 142 "github.com/ppphp/yayagf/pkg/handlers" 143 "log" 144 ) 145 146 func main() { 147 // a static router 148 if ss, err := handlers.ServeStaticDirectory(config.GetConfig().Static); err != nil { 149 log.Println(err) 150 } else { 151 for _, s := range ss { 152 r.GET(s.GetPath(), s.GetGinHandler()) 153 if filepath.Clean(s.GetPath()) == "/index.html" { 154 r.GET("/", s.GetGinHandler()) 155 } 156 } 157 } 158 159 // a pprof generator 160 for _, s := range handlers.PProfHandlers { 161 r.Group("pprof").GET(s.GetPath(), s.GetGinHandler()) 162 } 163 } 164 ``` 165 166 ### monitoring 167 168 only monitor dynamic metrics 169 170 #### system 171 - cpu 172 - memory 173 - load average 174 - disk 175 176 #### runtime 177 - process cpu 178 - process mem 179 - process fd 180 - thread 181 - goroutine 182 - gc 183 184 #### handler 185 - outer services (rest) 186 - inner services (rpc) 187 188 #### storage 189 - db 190 - redis 191 - thirdparty services (rpc) 192 193 ## testing 194 195 WIP 196 197 ## performance 198 199 i don't care. 200 201 ## packages 202 203 package to docker // TODO some others