Skip to content

Commit 47dab78

Browse files
committed
chore: format with gofumpt
1 parent a1a70e9 commit 47dab78

Some content is hidden

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

51 files changed

+316
-273
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# role to be defined.
2+
linters-settings:
3+
lll:
4+
line-length: 120 # Set your desired maximum line length here

cmd/notifier.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"context"
2525
"encoding/json"
2626
"fmt"
27-
"github.com/go-redis/redis/v8"
2827
"log"
2928

29+
"github.com/go-redis/redis/v8"
30+
3031
"fractale/fractal6.go/graph"
3132
"fractale/fractal6.go/graph/model"
3233
"fractale/fractal6.go/web/middleware"
@@ -37,8 +38,8 @@ var REDIS_ADDRESS string = "localhost:6379"
3738

3839
var cache *redis.Client = redis.NewClient(&redis.Options{
3940
Addr: REDIS_ADDRESS,
40-
//Password: "", // no password set
41-
//DB: 0, // use default DB
41+
// Password: "", // no password set
42+
// DB: 0, // use default DB
4243
})
4344

4445
var ctx = context.Background()
@@ -116,7 +117,7 @@ func processContractNotification(msg *redis.Message) {
116117

117118
// @deprecated
118119
// Add a little sleep to wait for UpdateContractHook as it writes after publishing
119-
//time.Sleep(1 * time.Second)
120+
// time.Sleep(1 * time.Second)
120121

121122
// Push notification
122123
if err := graph.PushContractNotifications(notif); err != nil {

cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
package cmd
2222

2323
import (
24+
"os"
25+
"strings"
2426
//"fmt"
2527
"github.com/spf13/cobra"
2628
"github.com/spf13/viper"
27-
"os"
28-
"strings"
2929

3030
"fractale/fractal6.go/tools"
3131
"fractale/fractal6.go/web/auth"
@@ -87,7 +87,7 @@ func init() {
8787
// Run the root command.
8888
func Run() {
8989
if err := rootCmd.Execute(); err != nil {
90-
//fmt.Fprintf(os.Stderr, "%v\n", err)
90+
// fmt.Fprintf(os.Stderr, "%v\n", err)
9191
os.Exit(-1)
9292
}
9393
}

cmd/server.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@
2121
package cmd
2222

2323
import (
24+
"log"
25+
"net/http"
26+
"time"
2427
//"fmt"
2528
"github.com/go-chi/chi/v5"
2629
"github.com/go-chi/chi/v5/middleware"
2730
"github.com/rs/cors"
2831
"github.com/spf13/viper"
29-
"log"
30-
"net/http"
31-
"time"
3232

3333
"fractale/fractal6.go/web"
3434
"fractale/fractal6.go/web/auth"
3535
handle6 "fractale/fractal6.go/web/handlers"
3636
middle6 "fractale/fractal6.go/web/middleware"
3737
)
3838

39-
var tkMaster *auth.Jwt
40-
var buildMode string
39+
var (
40+
tkMaster *auth.Jwt
41+
buildMode string
42+
)
4143

4244
func init() {
4345
// Get env mode
@@ -71,9 +73,9 @@ func RunServer() {
7173
// for more ideas, see: https://developer.github.com/v3/#cross-origin-resource-sharing
7274
cors := cors.New(cors.Options{
7375
AllowedOrigins: allowedOrigins,
74-
//AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
75-
//AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
76-
//ExposedHeaders: []string{"Link"},
76+
// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
77+
// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
78+
// ExposedHeaders: []string{"Link"},
7779
AllowCredentials: true,
7880
MaxAge: 300, // Maximum value not ignored by any of major browsers
7981
})
@@ -82,7 +84,7 @@ func RunServer() {
8284
r.Use(middleware.RequestID)
8385
r.Use(middleware.RealIP)
8486
r.Use(cors.Handler)
85-
//r.Use(middle6.RequestContextMiddleware) // Set context info
87+
// r.Use(middle6.RequestContextMiddleware) // Set context info
8688
// JWT //r.Use(jwtauth.Verifier(tkMaster.GetAuth()))
8789
r.Use(middle6.JwtVerifier(tkMaster.GetAuth())) // Seek, verify and validate JWT token
8890
r.Use(middle6.JwtDecode) // Set user claims
@@ -106,7 +108,7 @@ func RunServer() {
106108
}()
107109
secured := r.Group(nil)
108110
secured.Use(middle6.CheckBearer)
109-
//secured.Handle("/metrics", promhttp.Handler()) // inclue Go collection metrics
111+
// secured.Handle("/metrics", promhttp.Handler()) // inclue Go collection metrics
110112
secured.Handle("/metrics", handle6.InstruHandler())
111113
}
112114

@@ -124,7 +126,7 @@ func RunServer() {
124126

125127
// Auth API
126128
r.Group(func(r chi.Router) {
127-
//r.Use(middle6.EnsurePostMethod)
129+
// r.Use(middle6.EnsurePostMethod)
128130
r.Route("/auth", func(r chi.Router) {
129131
// User
130132
r.Post("/signup", handle6.Signup)
@@ -151,13 +153,12 @@ func RunServer() {
151153
// Rest API
152154
r.Group(func(r chi.Router) {
153155
r.Route("/q", func(r chi.Router) {
154-
155156
// Special recursive query
156157
r.Group(func(r chi.Router) {
157158
// Those data are not secured by now, and anyone can
158159
// query them recursively, but as there are not sensitive
159160
// and set them public for now.
160-
//r.Use(middle6.CheckRecursiveQueryRights)
161+
// r.Use(middle6.CheckRecursiveQueryRights)
161162
r.Post("/sub_nodes", handle6.SubNodes)
162163
r.Post("/sub_members", handle6.SubMembers)
163164
r.Post("/top_labels", handle6.TopLabels)
@@ -170,7 +171,7 @@ func RunServer() {
170171
r.Group(func(r chi.Router) {
171172
// The filtering is done directly in the query resolver as
172173
// doing it here required to rewrite the body, which seems difficult ?!
173-
//r.Use(middle6.CheckTensionQueryRights)
174+
// r.Use(middle6.CheckTensionQueryRights)
174175
r.Post("/tensions_light", handle6.TensionsLight)
175176
r.Post("/tensions_int", handle6.TensionsInt)
176177
r.Post("/tensions_ext", handle6.TensionsExt)

cmd/user.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ package cmd
2222

2323
import (
2424
"fmt"
25-
"github.com/spf13/cobra"
2625
"strings"
2726

27+
"github.com/spf13/cobra"
28+
2829
"fractale/fractal6.go/db"
2930
"fractale/fractal6.go/graph/model"
3031
"fractale/fractal6.go/tools"
3132
"fractale/fractal6.go/web/auth"
3233
)
3334

34-
var lang string
35-
var creds model.UserCreds
35+
var (
36+
lang string
37+
creds model.UserCreds
38+
)
3639

3740
var addUser = &cobra.Command{
3841
Use: "adduser USERNAME EMAIL PASSWORD [--lang LANG]",

db/dgraph.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ import (
2626
"crypto/rsa"
2727
"encoding/json"
2828
"fmt"
29-
"github.com/go-chi/jwtauth/v5"
30-
"github.com/mitchellh/mapstructure"
31-
"github.com/spf13/viper"
3229
"io/ioutil"
3330
"log"
3431
"net/http"
3532
"os"
3633
"strings"
3734
"text/template"
3835
"time"
36+
37+
"github.com/go-chi/jwtauth/v5"
38+
"github.com/mitchellh/mapstructure"
39+
"github.com/spf13/viper"
40+
3941
//"github.com/vektah/gqlparser/v2/gqlerror"
4042
"github.com/dgraph-io/dgo/v200"
4143
"github.com/dgraph-io/dgo/v200/protos/api"
@@ -46,10 +48,12 @@ import (
4648
. "fractale/fractal6.go/tools"
4749
)
4850

49-
var dgraphPrivateKey *rsa.PrivateKey
50-
var dgraphPublicKey *rsa.PublicKey
51-
var buildMode string
52-
var DOMAIN string
51+
var (
52+
dgraphPrivateKey *rsa.PrivateKey
53+
dgraphPublicKey *rsa.PublicKey
54+
buildMode string
55+
DOMAIN string
56+
)
5357

5458
// Database client
5559
var DB *Dgraph
@@ -162,8 +166,8 @@ func initDB() *Dgraph {
162166
panic("Viper error: not host found")
163167
} else {
164168
// @DEBUG: log level, Viper!
165-
//fmt.Println("Dgraph Graphql addr:", dgraphApiAddr)
166-
//fmt.Println("Dgraph Grpc addr:", grpcAddr)
169+
// fmt.Println("Dgraph Graphql addr:", dgraphApiAddr)
170+
// fmt.Println("Dgraph Grpc addr:", grpcAddr)
167171
}
168172

169173
return &Dgraph{
@@ -211,7 +215,7 @@ func (dg Dgraph) getDgraphClient() (dgClient *dgo.Dgraph, cancelFunc func()) {
211215
}
212216

213217
dgClient = dgo.NewDgraphClient(api.NewDgraphClient(conn))
214-
//ctx := context.Background()
218+
// ctx := context.Background()
215219

216220
//// Perform login call. If the Dgraph cluster does not have ACL and
217221
//// enterprise features enabled, this call should be skipped.
@@ -257,13 +261,13 @@ func (dg Dgraph) BuildGqlToken(uctx model.UserCtx, t time.Duration) string {
257261
if *d.RoleType == model.RoleTypeOwner {
258262
ownids = append(ownids, rid)
259263
// Owner is also a member !
260-
//continue
264+
// continue
261265
}
262266
if _, v := check[rid]; !v {
263267
// @DEBUG: if pending is not included here, invited user, or author of tension created with BOT
264268
// won't be able to see on tensins. But, authorizing it, make give a visibity hole for private circle
265269
// that can be seen by **self-invited** user.
266-
//if *d.RoleType != model.RoleTypePending && *d.RoleType != model.RoleTypeRetired {
270+
// if *d.RoleType != model.RoleTypePending && *d.RoleType != model.RoleTypeRetired {
267271
if *d.RoleType != model.RoleTypeRetired {
268272
check[rid] = true
269273
rootids = append(rootids, rid)
@@ -295,7 +299,7 @@ func (dg Dgraph) BuildGqlToken(uctx model.UserCtx, t time.Duration) string {
295299

296300
// Create token
297301
tkm := jwtauth.New("RS256", dgraphPrivateKey, dgraphPublicKey)
298-
//tkm := jwtauth.New("HS256", []byte("checkJwkToken_or_pubkey"), []byte("checkJwkToken_or_pubkey"))
302+
// tkm := jwtauth.New("HS256", []byte("checkJwkToken_or_pubkey"), []byte("checkJwkToken_or_pubkey"))
299303
_, token, err := tkm.Encode(claims)
300304
if err != nil {
301305
panic("Dgraph JWT error: " + err.Error())
@@ -342,9 +346,9 @@ func (dg Dgraph) QueryDql(op string, maps map[string]string) (*api.Response, err
342346
// @DEBUG LEVEL
343347
fmt.Println(op)
344348
}
345-
//fmt.Println(string(q))
349+
// fmt.Println(string(q))
346350
res, err := txn.Query(ctx, q)
347-
//fmt.Println(res)
351+
// fmt.Println(res)
348352
return res, err
349353
}
350354

@@ -397,8 +401,8 @@ func (dg Dgraph) MutateWithQueryDql3(q QueryMut, maps map[string]string) (*api.R
397401
mutations = append(mutations, &mu)
398402
}
399403

400-
//fmt.Println(query)
401-
//fmt.Println(mutations)
404+
// fmt.Println(query)
405+
// fmt.Println(mutations)
402406

403407
if len(q.M) == 0 {
404408
return txn.Query(ctx, query)
@@ -426,9 +430,9 @@ func (dg Dgraph) QueryGql(uctx model.UserCtx, op string, reqInput map[string]str
426430

427431
// Send the dgraph request and follow the results
428432
res := &GqlRes{}
429-
//fmt.Println("request ->", string(q))
433+
// fmt.Println("request ->", string(q))
430434
err := dg.postql(uctx, []byte(q), res)
431-
//fmt.Println("response ->", res)
435+
// fmt.Println("response ->", res)
432436
if err != nil {
433437
return err
434438
}
@@ -447,7 +451,7 @@ func (dg Dgraph) QueryGql(uctx model.UserCtx, op string, reqInput map[string]str
447451
// @DEBUG: see bug #3c3f1f7
448452
// Not needed since version 5.0.10 of elm-graphql that do not used hashes by defaut.
449453
// Not that alias won be supported since we know to handle it with gqlgen resolver.
450-
//CleanAliasedMapHook(),
454+
// CleanAliasedMapHook(),
451455
ToUnionHookFunc(),
452456
),
453457
}
@@ -463,7 +467,7 @@ func (dg Dgraph) QueryGql(uctx model.UserCtx, op string, reqInput map[string]str
463467

464468
if res.Errors != nil {
465469
err, _ := json.Marshal(res.Errors)
466-
//return fmt.Errorf(string(err))
470+
// return fmt.Errorf(string(err))
467471
return &GraphQLError{string(err)}
468472
}
469473
return err

0 commit comments

Comments
 (0)