Skip to content

Commit 29f80e7

Browse files
authored
chore: code format with make build (#56)
1 parent c4bfa07 commit 29f80e7

File tree

319 files changed

+2736
-2792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+2736
-2792
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ all-platform: clean config update-vfs cross-build-all-platform restore-generated
203203
cross-build-all-platform: clean config build-bsd build-linux build-darwin build-win restore-generated-file
204204

205205
format:
206-
go fmt $$(go list ./... | grep -v /vendor/)
206+
@echo "formatting code"
207+
GOPATH=$(NEWGOPATH) $(GO) fmt $$(GOPATH=$(NEWGOPATH) $(GO) list ./...)
207208

208209
clean_data:
209210
rm -rif dist
@@ -263,7 +264,7 @@ update-vfs:
263264
@if [ ! -e $(VFS_PATH) ]; then (cd $(FRAMEWORK_FOLDER) && OFFLINE_BUILD=true make build-cmd && cp bin/vfs $(VFS_PATH)) fi
264265
@if [ -d $(APP_STATIC_FOLDER) ]; then echo "generate static files";(cd $(APP_STATIC_FOLDER) && $(VFS_PATH) -ignore="static.go|.DS_Store" -o static.go -pkg $(APP_STATIC_PACKAGE) . ) fi
265266

266-
config: init update-vfs update-generated-file update-plugins
267+
config: init format update-vfs update-generated-file update-plugins
267268
@echo "update configs"
268269
@# $(GO) env
269270
@mkdir -p $(OUTPUT_DIR)

app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const (
9191

9292
func NewApp(name, desc, ver, buildNumber, commit, buildDate, eolDate, terminalHeader, terminalFooter string) *App {
9393
if terminalFooter == "" {
94-
terminalFooter = (" __ _ __ ____ __ _ __ __ \n")
94+
terminalFooter = (" __ _ __ ____ __ _ __ __ \n")
9595
terminalFooter += (" / // |/ // __// // |/ // / \n")
9696
terminalFooter += (" / // || // _/ / // || // / \n")
9797
terminalFooter += ("/_//_/|_//_/ /_//_/|_//_/ \n\n")

cmd/genfastjson/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ package main
4040
//➜ model git:(master) ✗ ../../../../cmd/generate-fastjson/generate-fastjson -o generated.go .
4141
//generated 3 methods in "generated.go"
4242

43-
44-
4543
import (
4644
"bytes"
4745
"flag"
@@ -424,7 +422,7 @@ func isNonZero(expr string, t types.Type) string {
424422
zero = "0"
425423
}
426424
default:
427-
fmt.Println(expr,t)
425+
fmt.Println(expr, t)
428426
panic(fmt.Errorf("unhandled type %T", t))
429427
}
430428
return fmt.Sprintf("%s != %s", expr, zero)

cmd/plugin-discovery/main.go

+14-15
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Options:
4646
`[1:]
4747

4848
var (
49-
pkg string
50-
importPrefix string
51-
outFile string
52-
pluginDirs stringSliceFlag
49+
pkg string
50+
importPrefix string
51+
outFile string
52+
pluginDirs stringSliceFlag
5353
)
5454

5555
func init() {
@@ -69,7 +69,7 @@ func main() {
6969
}
7070

7171
// Build import paths.
72-
var imports =map[string]util.KV{}
72+
var imports = map[string]util.KV{}
7373
for _, dir := range pluginDirs {
7474

7575
libRegEx, e := regexp.Compile(".*.go$")
@@ -79,7 +79,7 @@ func main() {
7979

8080
e = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
8181

82-
if path==outFile{
82+
if path == outFile {
8383
return nil
8484
}
8585

@@ -90,7 +90,7 @@ func main() {
9090
}
9191
if hasInitMethod(filepath.Join(path)) {
9292
imports[filepath.ToSlash(
93-
filepath.Join(importPrefix, filepath.Dir(path)))] =util.KV{}
93+
filepath.Join(importPrefix, filepath.Dir(path)))] = util.KV{}
9494

9595
return nil
9696
}
@@ -102,13 +102,13 @@ func main() {
102102
}
103103
}
104104

105-
importKeys:=util.GetMapKeys(imports)
105+
importKeys := util.GetMapKeys(imports)
106106

107107
// Populate the template.
108108
var buf bytes.Buffer
109109
err := Template.Execute(&buf, Data{
110-
Package: pkg,
111-
Imports: importKeys,
110+
Package: pkg,
111+
Imports: importKeys,
112112
})
113113
if err != nil {
114114
log.Fatalf("Failed executing template: %v", err)
@@ -133,7 +133,7 @@ func usageFlag() {
133133
var Template = template.Must(template.New("normalizations").Funcs(map[string]interface{}{
134134
"trim": strings.TrimSpace,
135135
}).Parse(
136-
`/// GENERATED CODE BY PLUGIN DISCOVERY- DO NOT EDIT.
136+
`/// GENERATED CODE BY PLUGIN DISCOVERY- DO NOT EDIT.
137137
138138
package {{ .Package }}
139139
@@ -145,11 +145,11 @@ import (
145145
`[1:]))
146146

147147
type Data struct {
148-
Package string
149-
Imports []string
148+
Package string
149+
Imports []string
150150
}
151151

152-
//stringSliceFlag is a flag type that allows more than one value to be specified.
152+
// stringSliceFlag is a flag type that allows more than one value to be specified.
153153
type stringSliceFlag []string
154154

155155
func (f *stringSliceFlag) String() string { return strings.Join(*f, ",") }
@@ -183,7 +183,6 @@ func hasInitMethod(file string) bool {
183183
return false
184184
}
185185

186-
187186
// FindFiles return a list of file matching the given glob patterns.
188187
func FindFiles(globs ...string) ([]string, error) {
189188
var configFiles []string

cmd/vfs/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ func main() {
150150
dirs[b] = true
151151
}
152152

153-
var buf= &bytes.Buffer{}
154-
reader:=bytes.NewBuffer(f.data)
155-
err=zstd.Compress(reader, buf)
156-
if err!=nil{
153+
var buf = &bytes.Buffer{}
154+
reader := bytes.NewBuffer(f.data)
155+
err = zstd.Compress(reader, buf)
156+
if err != nil {
157157
panic(err)
158158
}
159159

cmd/zstd/main.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,44 @@ package main
3131

3232
import (
3333
"flag"
34+
log "github.com/cihub/seelog"
3435
"infini.sh/framework/core/util"
3536
"infini.sh/framework/core/util/zstd"
36-
log "github.com/cihub/seelog"
3737
"sync"
3838
)
3939

40-
41-
4240
func main() {
4341

4442
path := flag.String("path", "data", "the data path")
4543
op := flag.String("op", "compress", "compress or decompress")
4644
flag.Parse()
4745

48-
files,err:=util.ListAllFiles(*path)
46+
files, err := util.ListAllFiles(*path)
4947
if err != nil {
5048
panic(err)
5149
}
5250

53-
if *op=="compress"{
51+
if *op == "compress" {
5452
for _, file := range files {
55-
if !util.SuffixStr(file,suffix){
56-
err:=zstd.CompressFile(file,file+suffix)
57-
if err!=nil{
53+
if !util.SuffixStr(file, suffix) {
54+
err := zstd.CompressFile(file, file+suffix)
55+
if err != nil {
5856
log.Error(err)
5957
}
6058
}
6159
}
62-
}else{
60+
} else {
6361
for _, file := range files {
64-
if util.SuffixStr(file,suffix){
65-
err:=zstd.DecompressFile(&locker,file,util.TrimRightStr(file,suffix))
66-
if err!=nil{
62+
if util.SuffixStr(file, suffix) {
63+
err := zstd.DecompressFile(&locker, file, util.TrimRightStr(file, suffix))
64+
if err != nil {
6765
log.Error(err)
6866
}
6967
}
7068
}
7169
}
7270

7371
}
74-
var suffix=".zstd"
75-
var locker=sync.RWMutex{}
72+
73+
var suffix = ".zstd"
74+
var locker = sync.RWMutex{}

core/api/api.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func StartAPI() {
223223

224224
router.NotFound = notfoundHandler
225225

226-
tlsCfg:=apiConfig.TLSConfig
226+
tlsCfg := apiConfig.TLSConfig
227227

228228
schema := "http://"
229229
if tlsCfg.TLSEnabled {
@@ -232,7 +232,7 @@ func StartAPI() {
232232
log.Trace("using tls connection")
233233

234234
cfg, err := GetServerTLSConfig(&tlsCfg)
235-
if err!=nil{
235+
if err != nil {
236236
panic(err)
237237
}
238238

@@ -312,4 +312,3 @@ func StartAPI() {
312312
log.Info("api server listen at: ", schema, listenAddress)
313313

314314
}
315-

core/api/certs.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"encoding/pem"
3535
"github.com/caddyserver/certmagic"
3636
"github.com/cihub/seelog"
37+
log "github.com/cihub/seelog"
3738
"github.com/libdns/tencentcloud"
3839
"go.uber.org/zap"
3940
"infini.sh/framework/core/config"
@@ -43,7 +44,6 @@ import (
4344
"io/ioutil"
4445
"os"
4546
"path"
46-
log "github.com/cihub/seelog"
4747
"time"
4848
)
4949

@@ -75,7 +75,7 @@ func GetServerTLSConfig(tlsCfg *config.TLSConfig) (*tls.Config, error) {
7575
}
7676

7777
if tlsCfg.AutoIssue.Enabled && (tlsCfg.TLSCertFile == "" && tlsCfg.TLSKeyFile == "") {
78-
AutoIssueTLSCertificates(tlsCfg,cfg)
78+
AutoIssueTLSCertificates(tlsCfg, cfg)
7979
} else {
8080
//try self-signed certs
8181
if tlsCfg.TLSCertFile == "" && tlsCfg.TLSKeyFile == "" {
@@ -113,7 +113,6 @@ func GetServerTLSConfig(tlsCfg *config.TLSConfig) (*tls.Config, error) {
113113
}
114114
}
115115

116-
117116
//load cert files
118117
cfg.Certificates = make([]tls.Certificate, 1)
119118
cfg.Certificates[0], err = tls.LoadX509KeyPair(tlsCfg.TLSCertFile, tlsCfg.TLSKeyFile)
@@ -138,10 +137,10 @@ func GetServerTLSConfig(tlsCfg *config.TLSConfig) (*tls.Config, error) {
138137
return cfg, err
139138
}
140139

141-
func AutoIssueTLSCertificates(tlsCfg *config.TLSConfig,cfg *tls.Config) {
140+
func AutoIssueTLSCertificates(tlsCfg *config.TLSConfig, cfg *tls.Config) {
142141
zapCfg := zap.NewProductionConfig()
143142

144-
if !global.Env().IsDebug{
143+
if !global.Env().IsDebug {
145144
zapCfg.Level = zap.NewAtomicLevelAt(zap.WarnLevel)
146145
}
147146

core/api/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ func init() {
346346
panic(err)
347347
}
348348

349-
if clientCfg.Proxy.OverrideSystemProxy{
350-
log.Debugf("override system proxy settings: %v %s",util.MustToJSON(clientCfg.Proxy.DefaultProxyConfig))
349+
if clientCfg.Proxy.OverrideSystemProxy {
350+
log.Debugf("override system proxy settings: %v %s", util.MustToJSON(clientCfg.Proxy.DefaultProxyConfig))
351351
UpdateProxyEnvironment(&clientCfg.Proxy.DefaultProxyConfig)
352352
}
353353

core/api/filter/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ limitations under the License.
3838
*/
3939

4040
package filter
41+
4142
//
4243
//import (
4344
// "fmt"

core/api/filter/rate_limit.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ limitations under the License.
3838
*/
3939

4040
package filter
41+
4142
//
4243
//import (
4344
// "fmt"

core/api/gzip/gizp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,4 @@ func parseCoding(s string) (coding string, qvalue float64, err error) {
556556
}
557557

558558
return
559-
}
559+
}

core/api/gzip/gizp_go18.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// You should have received a copy of the GNU Affero General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

24+
//go:build go1.8
2425
// +build go1.8
2526

2627
/* Copyright © INFINI Ltd. All rights reserved.

core/api/handler.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (handler Handler) MustGetParameter(w http.ResponseWriter, r *http.Request,
220220
panic("URL is nil")
221221
}
222222

223-
v:= r.URL.Query().Get(key)
223+
v := r.URL.Query().Get(key)
224224

225225
if len(v) == 0 {
226226
panic("missing parameter " + key)
@@ -392,7 +392,6 @@ func (handler Handler) WriteGetMissingJSON(w http.ResponseWriter, id string) err
392392
}, 404)
393393
}
394394

395-
396395
func (handler Handler) Redirect(w http.ResponseWriter, r *http.Request, url string) {
397396
http.Redirect(w, r, url, http.StatusSeeOther)
398397
}

core/api/recovery.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ func (h recoveryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
8989
v = r.(string)
9090
}
9191

92-
errObj:=util.MapStr{
93-
"status":http.StatusInternalServerError,
94-
"reason":v,
92+
errObj := util.MapStr{
93+
"status": http.StatusInternalServerError,
94+
"reason": v,
9595
}
9696

97-
if global.Env().SystemConfig.APIConfig.VerboseErrorRootCause{
98-
errObj["root_cause"]=string(debug.Stack())
97+
if global.Env().SystemConfig.APIConfig.VerboseErrorRootCause {
98+
errObj["root_cause"] = string(debug.Stack())
9999
}
100100

101101
var payload = util.MapStr{
@@ -107,7 +107,7 @@ func (h recoveryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
107107
}
108108
w.Write(payloadBytes)
109109

110-
if global.Env().IsDebug{
110+
if global.Env().IsDebug {
111111
h.log(v)
112112
}
113113
}

core/api/router/params_go17.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// You should have received a copy of the GNU Affero General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

24+
//go:build go1.7
2425
// +build go1.7
2526

2627
package httprouter

core/api/router/params_legacy.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// You should have received a copy of the GNU Affero General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

24+
//go:build !go1.7
2425
// +build !go1.7
2526

2627
package httprouter

0 commit comments

Comments
 (0)