From 12fb92cb6552bc0ea2a5abe81186bdd5d738e3b5 Mon Sep 17 00:00:00 2001 From: Radhakrishna Sanka Date: Fri, 12 Jul 2024 16:43:36 +0530 Subject: [PATCH] Undid struct naming that pushed stuff to be public --- cmd/cmd_seed.go | 12 +++--- conf/config.go | 4 +- core/internal/graph/lex.go | 64 ++++++++++++++++---------------- core/internal/graph/parse.go | 16 ++++---- core/internal/graph/schema.go | 2 +- core/internal/sdata/dwg.go | 26 ++++++------- core/internal/sdata/schema.go | 16 ++++---- core/internal/util/graph.go | 4 +- core/internal/util/heap.go | 30 +++++++-------- core/osfs.go | 12 +++--- core/remote_api.go | 16 ++++---- core/subs.go | 58 ++++++++++++++--------------- serv/admin.go | 6 +-- serv/api.go | 36 +++++++++--------- serv/db.go | 12 +++--- serv/deploy.go | 6 +-- serv/filewatch.go | 2 +- serv/health.go | 2 +- serv/http.go | 12 +++--- serv/init.go | 12 +++--- serv/internal/secrets/decrypt.go | 4 +- serv/internal/secrets/edit.go | 20 +++++----- serv/internal/secrets/init.go | 2 +- serv/internal/secrets/rotate.go | 4 +- serv/internal/secrets/run.go | 8 ++-- serv/iplimiter.go | 2 +- serv/routes.go | 2 +- serv/serv.go | 6 +-- serv/ws.go | 6 +-- 29 files changed, 201 insertions(+), 201 deletions(-) diff --git a/cmd/cmd_seed.go b/cmd/cmd_seed.go index 2898b796..d50f0f40 100644 --- a/cmd/cmd_seed.go +++ b/cmd/cmd_seed.go @@ -212,13 +212,13 @@ func graphQLFunc(gj *core.GraphJin, query string, data interface{}, opt map[stri return val } -type CSVSource struct { +type csvSource struct { rows [][]string i int } // NewCSVSource creates a new CSV source -func NewCSVSource(filename string, sep rune) (*CSVSource, error) { +func NewCSVSource(filename string, sep rune) (*csvSource, error) { f, err := os.Open(filename) if err != nil { return nil, err @@ -238,14 +238,14 @@ func NewCSVSource(filename string, sep rune) (*CSVSource, error) { return nil, err } - return &CSVSource{rows: rows}, nil + return &csvSource{rows: rows}, nil } -func (c *CSVSource) Next() bool { +func (c *csvSource) Next() bool { return c.i < len(c.rows) } -func (c *CSVSource) Values() ([]interface{}, error) { +func (c *csvSource) Values() ([]interface{}, error) { var vals []interface{} var err error @@ -286,7 +286,7 @@ func isDigit(v string) bool { return true } -func (c *CSVSource) Err() error { +func (c *csvSource) Err() error { return nil } diff --git a/conf/config.go b/conf/config.go index aaab65f2..dcd12654 100644 --- a/conf/config.go +++ b/conf/config.go @@ -9,7 +9,7 @@ import ( "gopkg.in/yaml.v3" ) -type ConfigInfo struct { +type configInfo struct { Inherits string } @@ -25,7 +25,7 @@ func NewConfig(configPath, configFile string) (c *core.Config, err error) { // NewConfigWithFS creates a new config object using the provided filesystem func NewConfigWithFS(fs core.FS, configFile string) (c *core.Config, err error) { c = &core.Config{FS: fs} - var ci ConfigInfo + var ci configInfo if err = readConfig(fs, configFile, &ci); err != nil { return diff --git a/core/internal/graph/lex.go b/core/internal/graph/lex.go index 0723baae..8257c6fc 100644 --- a/core/internal/graph/lex.go +++ b/core/internal/graph/lex.go @@ -30,8 +30,8 @@ var ( // this template was parsed. type Pos int -// Item represents a token or text string returned from the scanner. -type Item struct { +// item represents a token or text string returned from the scanner. +type item struct { _type MType // The type of this item. pos Pos // The starting position, in bytes, of this item in the input string. val []byte // The value of this item. @@ -80,29 +80,29 @@ var punctuators = map[rune]MType{ const eof = -1 // StateFn represents the state of the scanner as a function that returns the next state. -type StateFn func(*Lexer) StateFn +type StateFn func(*lexer) StateFn -// Lexer holds the state of the scanner. -type Lexer struct { +// lexer holds the state of the scanner. +type lexer struct { input []byte // the string being scanned pos Pos // current position in the input start Pos // start position of this item width Pos // width of last rune read from input - items []Item // array of scanned items - itemsA [50]Item + items []item // array of scanned items + itemsA [50]item line int16 // 1+number of newlines seen err error } -var zeroLex = Lexer{} +var zeroLex = lexer{} // Reset resets the lexer to scan a new input string. -func (l *Lexer) Reset() { +func (l *lexer) Reset() { *l = zeroLex } // next returns the next byte in the input. -func (l *Lexer) next() rune { +func (l *lexer) next() rune { if int(l.pos) >= len(l.input) { l.width = 0 return eof @@ -117,14 +117,14 @@ func (l *Lexer) next() rune { } // peek returns but does not consume the next rune in the input. -func (l *Lexer) peek() rune { +func (l *lexer) peek() rune { r := l.next() l.backup() return r } // backup steps back one rune. Can only be called once per call of next. -func (l *Lexer) backup() { +func (l *lexer) backup() { if l.pos != 0 { l.pos -= l.width // Correct newline count. @@ -135,13 +135,13 @@ func (l *Lexer) backup() { } // current returns the current bytes of the input. -func (l *Lexer) current() []byte { +func (l *lexer) current() []byte { return l.input[l.start:l.pos] } // emit passes an item back to the client. -func (l *Lexer) emit(t MType) { - l.items = append(l.items, Item{t, l.start, l.current(), l.line}) +func (l *lexer) emit(t MType) { + l.items = append(l.items, item{t, l.start, l.current(), l.line}) // Some items contain text internally. If so, count their newlines. if t == itemStringVal { for i := l.start; i < l.pos; i++ { @@ -154,18 +154,18 @@ func (l *Lexer) emit(t MType) { } // emitL passes an item back to the client and lowercases the value. -func (l *Lexer) emitL(t MType) { +func (l *lexer) emitL(t MType) { lowercase(l.current()) l.emit(t) } // ignore skips over the pending input before this point. -func (l *Lexer) ignore() { +func (l *lexer) ignore() { l.start = l.pos } // accept consumes the next rune if it's from the valid set. -func (l *Lexer) accept(valid []byte) (rune, bool) { +func (l *lexer) accept(valid []byte) (rune, bool) { r := l.next() if r != eof && bytes.ContainsRune(valid, r) { return r, true @@ -175,7 +175,7 @@ func (l *Lexer) accept(valid []byte) (rune, bool) { } // acceptAlphaNum consumes a run of runes while they are alpha nums -func (l *Lexer) acceptAlphaNum() bool { +func (l *lexer) acceptAlphaNum() bool { n := 0 for r := l.next(); isAlphaNumeric(r); r = l.next() { n++ @@ -185,7 +185,7 @@ func (l *Lexer) acceptAlphaNum() bool { } // acceptComment consumes a run of runes while till the end of line -func (l *Lexer) acceptComment() { +func (l *lexer) acceptComment() { n := 0 for r := l.next(); !isEndOfLine(r); r = l.next() { n++ @@ -193,7 +193,7 @@ func (l *Lexer) acceptComment() { } // acceptRun consumes a run of runes from the valid set. -func (l *Lexer) acceptRun(valid []byte) { +func (l *lexer) acceptRun(valid []byte) { for bytes.ContainsRune(valid, l.next()) { } @@ -202,15 +202,15 @@ func (l *Lexer) acceptRun(valid []byte) { // errorf returns an error token and terminates the scan by passing // back a nil pointer that will be the next state, terminating l.nextItem. -func (l *Lexer) errorf(format string, args ...interface{}) StateFn { +func (l *lexer) errorf(format string, args ...interface{}) StateFn { l.err = fmt.Errorf(format, args...) - l.items = append(l.items, Item{itemError, l.start, l.input[l.start:l.pos], l.line}) + l.items = append(l.items, item{itemError, l.start, l.input[l.start:l.pos], l.line}) return nil } // lex creates a new scanner for the input string. -func lex(input []byte) (Lexer, error) { - var l Lexer +func lex(input []byte) (lexer, error) { + var l lexer if len(input) == 0 { return l, errors.New("empty query") @@ -229,14 +229,14 @@ func lex(input []byte) (Lexer, error) { } // run runs the state machine for the lexer. -func (l *Lexer) run() { +func (l *lexer) run() { for state := lexRoot; state != nil; { state = state(l) } } // lexInsideAction scans the elements inside action delimiters. -func lexRoot(l *Lexer) StateFn { +func lexRoot(l *lexer) StateFn { r := l.next() switch { @@ -290,7 +290,7 @@ func lexRoot(l *Lexer) StateFn { } // lexName scans a name. -func lexName(l *Lexer) StateFn { +func lexName(l *lexer) StateFn { for { r := l.next() @@ -320,7 +320,7 @@ func lexName(l *Lexer) StateFn { } // lexString scans a string. -func lexString(l *Lexer) StateFn { +func lexString(l *lexer) StateFn { if sr, ok := l.accept([]byte(quotesToken)); ok { l.ignore() @@ -354,7 +354,7 @@ func lexString(l *Lexer) StateFn { // lexNumber scans a number: decimal and float. This isn't a perfect number scanner // for instance it accepts "." and "0x0.2" and "089" - but when it's wrong the input // is invalid and the parser (via strconv) should notice. -func lexNumber(l *Lexer) StateFn { +func lexNumber(l *lexer) StateFn { if !l.scanNumber() { return l.errorf("bad number syntax: %q", l.input[l.start:l.pos]) } @@ -363,7 +363,7 @@ func lexNumber(l *Lexer) StateFn { } // scanNumber scans a number: decimal and float. -func (l *Lexer) scanNumber() bool { +func (l *lexer) scanNumber() bool { // Optional leading sign. l.accept(signsToken) l.acceptRun(digitToken) @@ -415,7 +415,7 @@ func lowercase(b []byte) { } // String returns a string representation of the item. -func (i Item) String() string { +func (i item) String() string { var v string switch i._type { diff --git a/core/internal/graph/parse.go b/core/internal/graph/parse.go index f3df1eeb..93efe9eb 100644 --- a/core/internal/graph/parse.go +++ b/core/internal/graph/parse.go @@ -116,13 +116,13 @@ type Parser struct { frags map[string]Fragment input []byte // the string being scanned pos int - items []Item + items []item json bool err error } func Parse(gql []byte) (op Operation, err error) { - var l Lexer + var l lexer if len(gql) == 0 { err = errors.New("empty query") @@ -758,11 +758,11 @@ func (p *Parser) parseValue() (*Node, error) { return node, nil } -func (p *Parser) val(v Item) string { +func (p *Parser) val(v item) string { return b2s(v.val) } -func (p *Parser) vall(v Item) string { +func (p *Parser) vall(v item) string { lowercase(v.val) return b2s(v.val) } @@ -811,18 +811,18 @@ func (p *Parser) peekVal(values ...[]byte) bool { return false } -func (p *Parser) curr() Item { +func (p *Parser) curr() item { if p.pos == -1 { - return Item{} + return item{} } return p.items[p.pos] } -func (p *Parser) next() Item { +func (p *Parser) next() item { n := p.pos + 1 if n >= len(p.items) { p.err = errEOT - return Item{_type: itemEOF} + return item{_type: itemEOF} } p.pos = n return p.items[p.pos] diff --git a/core/internal/graph/schema.go b/core/internal/graph/schema.go index e8f666ef..cf792935 100644 --- a/core/internal/graph/schema.go +++ b/core/internal/graph/schema.go @@ -30,7 +30,7 @@ type TField struct { } func ParseSchema(schema []byte) (s Schema, err error) { - var l Lexer + var l lexer if len(schema) == 0 { err = errors.New("empty schema") diff --git a/core/internal/sdata/dwg.go b/core/internal/sdata/dwg.go index 653e1b86..feb20fb6 100644 --- a/core/internal/sdata/dwg.go +++ b/core/internal/sdata/dwg.go @@ -30,15 +30,15 @@ func (s *DBSchema) addNode(t DBTable) int32 { s.tables = append(s.tables, t) n := s.relationshipGraph.AddNode() - s.tindex[(t.Schema + ":" + t.Name)] = NodeInfo{n} + s.tindex[(t.Schema + ":" + t.Name)] = nodeInfo{n} return n } // addAliases adds table aliases to the graph func (s *DBSchema) addAliases(t DBTable, nodeID int32, aliases []string) { for _, al := range aliases { - s.tindex[(t.Schema + ":" + al)] = NodeInfo{nodeID} - s.tableAliasIndex[al] = NodeInfo{nodeID} + s.tindex[(t.Schema + ":" + al)] = nodeInfo{nodeID} + s.tableAliasIndex[al] = nodeInfo{nodeID} } } @@ -181,7 +181,7 @@ func (s *DBSchema) addEdge(name string, edge TEdge, inSchema bool, return -1, err } - ei := EdgeInfo{nodeID: edge.From, edgeIDs: []int32{edgeID}} + ei := edgeInfo{nodeID: edge.From, edgeIDs: []int32{edgeID}} s.addEdgeInfo(name, ei) if inSchema { @@ -193,7 +193,7 @@ func (s *DBSchema) addEdge(name string, edge TEdge, inSchema bool, } // addEdgeInfo adds edge info to the index -func (s *DBSchema) addEdgeInfo(k string, ei EdgeInfo) { +func (s *DBSchema) addEdgeInfo(k string, ei edgeInfo) { if eiList, ok := s.edgesIndex[k]; ok { for i, v := range eiList { if v.nodeID != ei.nodeID { @@ -275,14 +275,14 @@ func (s *DBSchema) FindPath(from, to, through string) ([]TPath, error) { return path, nil } -// GraphResult represents a graph result -type GraphResult struct { - from, to EdgeInfo +// graphResult represents a graph result +type graphResult struct { + from, to edgeInfo edges []int32 } // between finds a path between two tables -func (s *DBSchema) between(from, to []EdgeInfo, through string) (res GraphResult, err error) { +func (s *DBSchema) between(from, to []edgeInfo, through string) (res graphResult, err error) { // TODO: picking a path // 1. first look for a direct edge to other table // 2. then find shortest path using relevant edges @@ -301,7 +301,7 @@ func (s *DBSchema) between(from, to []EdgeInfo, through string) (res GraphResult } // pickPath picks a path between two tables -func (s *DBSchema) pickPath(from, to EdgeInfo, through string) (res GraphResult, err error) { +func (s *DBSchema) pickPath(from, to edgeInfo, through string) (res graphResult, err error) { res.from = from res.to = to @@ -327,7 +327,7 @@ func (s *DBSchema) pickPath(from, to EdgeInfo, through string) (res GraphResult, } // pickEdges picks edges between two tables -func (s *DBSchema) pickEdges(path []int32, from, to EdgeInfo) (edges []int32, allFound bool) { +func (s *DBSchema) pickEdges(path []int32, from, to edgeInfo) (edges []int32, allFound bool) { pathLen := len(path) peID := int32(-2) // must be -2 so does not match default -1 @@ -392,7 +392,7 @@ func (s *DBSchema) pickThroughPath(paths [][]int32, through string) ([][]int32, } // pickLine picks a line between two tables -func pickLine(lines []util.Edge, ei EdgeInfo, peID int32) *util.Edge { +func pickLine(lines []util.Edge, ei edgeInfo, peID int32) *util.Edge { for _, v := range lines { for _, eid := range ei.edgeIDs { if v.ID == eid && v.OppID != peID { @@ -445,7 +445,7 @@ func (s *DBSchema) PrintLines(lines []util.Edge) { } // PrintEdgeInfo prints edge info -func (s *DBSchema) PrintEdgeInfo(e EdgeInfo) { +func (s *DBSchema) PrintEdgeInfo(e edgeInfo) { t := s.tables[e.nodeID] fmt.Printf("-- EdgeInfo %s %+v\n", t.Name, e.edgeIDs) diff --git a/core/internal/sdata/schema.go b/core/internal/sdata/schema.go index 0bb3cee2..31c9fac2 100644 --- a/core/internal/sdata/schema.go +++ b/core/internal/sdata/schema.go @@ -9,12 +9,12 @@ import ( "github.com/dosco/graphjin/core/v3/internal/util" ) -type EdgeInfo struct { +type edgeInfo struct { nodeID int32 edgeIDs []int32 } -type NodeInfo struct { +type nodeInfo struct { nodeID int32 } @@ -26,9 +26,9 @@ type DBSchema struct { tables []DBTable // tables virtualTables map[string]VirtualTable // for polymorphic relationships dbFunctions map[string]DBFunction // db functions - tindex map[string]NodeInfo // table index - tableAliasIndex map[string]NodeInfo // table alias index - edgesIndex map[string][]EdgeInfo // edges index + tindex map[string]nodeInfo // table index + tableAliasIndex map[string]nodeInfo // table alias index + edgesIndex map[string][]edgeInfo // edges index allEdges map[int32]TEdge // all edges relationshipGraph *util.Graph // relationship graph } @@ -78,9 +78,9 @@ func NewDBSchema( name: info.Name, virtualTables: make(map[string]VirtualTable), dbFunctions: make(map[string]DBFunction), - tindex: make(map[string]NodeInfo), - tableAliasIndex: make(map[string]NodeInfo), - edgesIndex: make(map[string][]EdgeInfo), + tindex: make(map[string]nodeInfo), + tableAliasIndex: make(map[string]nodeInfo), + edgesIndex: make(map[string][]edgeInfo), allEdges: make(map[int32]TEdge), relationshipGraph: util.NewGraph(), } diff --git a/core/internal/util/graph.go b/core/internal/util/graph.go index 0295f5cd..b2a9a0c1 100644 --- a/core/internal/util/graph.go +++ b/core/internal/util/graph.go @@ -89,7 +89,7 @@ func (g *Graph) AllPaths(from, to int32) [][]int32 { var limit int h := newHeap() - h.push(Path{weight: 0, parent: from, nodes: []int32{from}}) + h.push(path{weight: 0, parent: from, nodes: []int32{from}}) visited := make(map[[2]int32]struct{}) for len(*h.paths) > 0 { @@ -126,7 +126,7 @@ func (g *Graph) AllPaths(from, to int32) [][]int32 { } // We calculate cost so far and add in the weight (cost) of this edge. - p1 := Path{ + p1 := path{ weight: p.weight + 1, parent: pnode, nodes: append(append([]int32{}, p.nodes...), e), diff --git a/core/internal/util/heap.go b/core/internal/util/heap.go index f4901652..d63fb53e 100644 --- a/core/internal/util/heap.go +++ b/core/internal/util/heap.go @@ -4,24 +4,24 @@ import ( hp "container/heap" ) -type Path struct { +type path struct { weight int32 parent int32 nodes []int32 visited map[int32]struct{} } -type MinPath []Path +type minPath []path -func (h MinPath) Len() int { return len(h) } -func (h MinPath) Less(i, j int) bool { return h[i].weight < h[j].weight } -func (h MinPath) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +func (h minPath) Len() int { return len(h) } +func (h minPath) Less(i, j int) bool { return h[i].weight < h[j].weight } +func (h minPath) Swap(i, j int) { h[i], h[j] = h[j], h[i] } -func (h *MinPath) Push(x interface{}) { - *h = append(*h, x.(Path)) +func (h *minPath) Push(x interface{}) { + *h = append(*h, x.(path)) } -func (h *MinPath) Pop() interface{} { +func (h *minPath) Pop() interface{} { old := *h n := len(old) x := old[n-1] @@ -29,19 +29,19 @@ func (h *MinPath) Pop() interface{} { return x } -type Heap struct { - paths *MinPath +type heap struct { + paths *minPath } -func newHeap() *Heap { - return &Heap{paths: &MinPath{}} +func newHeap() *heap { + return &heap{paths: &minPath{}} } -func (h *Heap) push(p Path) { +func (h *heap) push(p path) { hp.Push(h.paths, p) } -func (h *Heap) pop() Path { +func (h *heap) pop() path { i := hp.Pop(h.paths) - return i.(Path) + return i.(path) } diff --git a/core/osfs.go b/core/osfs.go index fb41a6f0..9a8ed1c2 100644 --- a/core/osfs.go +++ b/core/osfs.go @@ -7,20 +7,20 @@ import ( "path/filepath" ) -type OSFS struct { +type osFS struct { basePath string } // NewOsFS creates a new OSFS instance -func NewOsFS(basePath string) *OSFS { return &OSFS{basePath: basePath} } +func NewOsFS(basePath string) *osFS { return &osFS{basePath: basePath} } // Get returns the file content -func (f *OSFS) Get(path string) ([]byte, error) { +func (f *osFS) Get(path string) ([]byte, error) { return os.ReadFile(filepath.Join(f.basePath, path)) } // Put writes the data to the file -func (f *OSFS) Put(path string, data []byte) (err error) { +func (f *osFS) Put(path string, data []byte) (err error) { path = filepath.Join(f.basePath, path) dir := filepath.Dir(path) @@ -36,14 +36,14 @@ func (f *OSFS) Put(path string, data []byte) (err error) { } // Exists checks if the file exists -func (f *OSFS) Exists(path string) (ok bool, err error) { +func (f *osFS) Exists(path string) (ok bool, err error) { path = filepath.Join(f.basePath, path) ok, err = f.exists(path) return } // Remove deletes the file -func (f *OSFS) exists(path string) (ok bool, err error) { +func (f *osFS) exists(path string) (ok bool, err error) { if _, err = os.Stat(path); err == nil { ok = true } else { diff --git a/core/remote_api.go b/core/remote_api.go index 99a2928b..73ef723f 100644 --- a/core/remote_api.go +++ b/core/remote_api.go @@ -11,24 +11,24 @@ import ( "github.com/dosco/graphjin/core/v3/internal/jsn" ) -// RemoteAPI struct defines a remote API endpoint -type RemoteAPI struct { +// remoteAPI struct defines a remote API endpoint +type remoteAPI struct { httpClient *http.Client URL string Debug bool PassHeaders []string - SetHeaders []RemoteHdrs + SetHeaders []remoteHdrs } -type RemoteHdrs struct { +type remoteHdrs struct { Name string Value string } // newRemoteAPI creates a new remote API endpoint -func newRemoteAPI(v map[string]interface{}, httpClient *http.Client) (*RemoteAPI, error) { - ra := RemoteAPI{ +func newRemoteAPI(v map[string]interface{}, httpClient *http.Client) (*remoteAPI, error) { + ra := remoteAPI{ httpClient: httpClient, } @@ -43,7 +43,7 @@ func newRemoteAPI(v map[string]interface{}, httpClient *http.Client) (*RemoteAPI } if v, ok := v["set_headers"].(map[string]string); ok { for k, v1 := range v { - rh := RemoteHdrs{Name: k, Value: v1} + rh := remoteHdrs{Name: k, Value: v1} ra.SetHeaders = append(ra.SetHeaders, rh) } } @@ -52,7 +52,7 @@ func newRemoteAPI(v map[string]interface{}, httpClient *http.Client) (*RemoteAPI } // Resolve function resolves a remote API request -func (r *RemoteAPI) Resolve(c context.Context, rr ResolverReq) ([]byte, error) { +func (r *remoteAPI) Resolve(c context.Context, rr ResolverReq) ([]byte, error) { uri := strings.ReplaceAll(r.URL, "$id", rr.ID) req, err := http.NewRequestWithContext(c, "GET", uri, nil) diff --git a/core/subs.go b/core/subs.go index ed26d811..ed149a46 100644 --- a/core/subs.go +++ b/core/subs.go @@ -27,7 +27,7 @@ const ( var minPollDuration = (200 * time.Millisecond) -type Sub struct { +type sub struct { k string s gstate js json.RawMessage @@ -35,27 +35,27 @@ type Sub struct { idgen uint64 add chan *Member del chan *Member - updt chan MMsg + updt chan mmsg - MVal + mval sync.Once } -type MVal struct { +type mval struct { params []json.RawMessage - mi []Minfo + mi []minfo res []chan *Result ids []uint64 } -type Minfo struct { +type minfo struct { dh [sha256.Size]byte values []interface{} // index of cursor value in the arguments array cindx int } -type MMsg struct { +type mmsg struct { id uint64 dh [sha256.Size]byte cursor string @@ -64,12 +64,12 @@ type MMsg struct { type Member struct { ns string params json.RawMessage - sub *Sub + sub *sub Result chan *Result done bool id uint64 vl []interface{} - mm MMsg + mm mmsg // index of cursor value in the arguments array cindx int } @@ -164,14 +164,14 @@ func (gj *GraphjinEngine) subscribe(c context.Context, r GraphqlReq) ( } k := s.key() - v, _ := gj.subs.LoadOrStore(k, &Sub{ + v, _ := gj.subs.LoadOrStore(k, &sub{ k: k, s: s, add: make(chan *Member), del: make(chan *Member), - updt: make(chan MMsg, 10), + updt: make(chan mmsg, 10), }) - sub := v.(*Sub) + sub := v.(*sub) sub.Do(func() { err = gj.initSub(c, sub) @@ -208,7 +208,7 @@ func (gj *GraphjinEngine) subscribe(c context.Context, r GraphqlReq) ( } // initSub function is called on the graphjin struct to initialize a subscription. -func (gj *GraphjinEngine) initSub(c context.Context, sub *Sub) (err error) { +func (gj *GraphjinEngine) initSub(c context.Context, sub *sub) (err error) { if err = sub.s.compile(); err != nil { return } @@ -229,7 +229,7 @@ func (gj *GraphjinEngine) initSub(c context.Context, sub *Sub) (err error) { } // subController function is called on the graphjin struct to control the subscription. -func (gj *GraphjinEngine) subController(sub *Sub) { +func (gj *GraphjinEngine) subController(sub *sub) { // remove subscription if controller exists defer gj.subs.Delete(sub.k) @@ -268,8 +268,8 @@ func (gj *GraphjinEngine) subController(sub *Sub) { } // addMember function is called on the sub struct to add a member. -func (s *Sub) addMember(m *Member) error { - mi := Minfo{cindx: m.cindx} +func (s *sub) addMember(m *Member) error { + mi := minfo{cindx: m.cindx} if mi.cindx != -1 { mi.values = m.vl } @@ -299,7 +299,7 @@ func (s *Sub) addMember(m *Member) error { } // deleteMember function is called on the sub struct to delete a member. -func (s *Sub) deleteMember(m *Member) { +func (s *sub) deleteMember(m *Member) { i, ok := s.findByID(m.id) if !ok { return @@ -319,7 +319,7 @@ func (s *Sub) deleteMember(m *Member) { } // updateMember function is called on the sub struct to update a member. -func (s *Sub) updateMember(msg MMsg) error { +func (s *sub) updateMember(msg mmsg) error { i, ok := s.findByID(msg.id) if !ok { return nil @@ -345,25 +345,25 @@ func (s *Sub) updateMember(msg MMsg) error { } // fanOutJobs function is called on the sub struct to fan out jobs. -func (s *Sub) fanOutJobs(gj *GraphjinEngine) { +func (s *sub) fanOutJobs(gj *GraphjinEngine) { switch { case len(s.ids) == 0: return case len(s.ids) <= maxMembersPerWorker: - go gj.subCheckUpdates(s, s.MVal, 0) + go gj.subCheckUpdates(s, s.mval, 0) default: // fan out chunks of work to multiple routines // separated by a random duration for i := 0; i < len(s.ids); i += maxMembersPerWorker { - gj.subCheckUpdates(s, s.MVal, i) + gj.subCheckUpdates(s, s.mval, i) } } } // subCheckUpdates function is called on the graphjin struct to check updates. -func (gj *GraphjinEngine) subCheckUpdates(sub *Sub, mv MVal, start int) { +func (gj *GraphjinEngine) subCheckUpdates(sub *sub, mv mval, start int) { // Do not use the `mval` embedded inside sub since // its not thread safe use the copy `mv mval`. @@ -442,7 +442,7 @@ func (gj *GraphjinEngine) subCheckUpdates(sub *Sub, mv MVal, start int) { } // subFirstQuery function is called on the graphjin struct to get the first query. -func (gj *GraphjinEngine) subFirstQuery(sub *Sub, m *Member) (MMsg, error) { +func (gj *GraphjinEngine) subFirstQuery(sub *sub, m *Member) (mmsg, error) { c := context.Background() // when params are not available we use a more optimized @@ -450,7 +450,7 @@ func (gj *GraphjinEngine) subFirstQuery(sub *Sub, m *Member) (MMsg, error) { // more details on this optimization are towards the end // of the function var js json.RawMessage - var mm MMsg + var mm mmsg var err error if sub.js != nil { @@ -483,7 +483,7 @@ func (gj *GraphjinEngine) subFirstQuery(sub *Sub, m *Member) (MMsg, error) { } // subNotifyMember function is called on the graphjin struct to notify a member. -func (gj *GraphjinEngine) subNotifyMember(s *Sub, mv MVal, j int, js json.RawMessage) { +func (gj *GraphjinEngine) subNotifyMember(s *sub, mv mval, j int, js json.RawMessage) { _, err := gj.subNotifyMemberEx(s, mv.mi[j].dh, mv.mi[j].cindx, @@ -495,10 +495,10 @@ func (gj *GraphjinEngine) subNotifyMember(s *Sub, mv MVal, j int, js json.RawMes } // subNotifyMemberEx function is called on the graphjin struct to notify a member. -func (gj *GraphjinEngine) subNotifyMemberEx(sub *Sub, +func (gj *GraphjinEngine) subNotifyMemberEx(sub *sub, dh [32]byte, cindx int, id uint64, rc chan *Result, js json.RawMessage, update bool, -) (MMsg, error) { - mm := MMsg{id: id} +) (mmsg, error) { + mm := mmsg{id: id} mm.dh = sha256.Sum256(js) if dh == mm.dh { @@ -604,7 +604,7 @@ func renderJSONArray(v []json.RawMessage) json.RawMessage { } // findByID function is called on the sub struct to find a member by id. -func (s *Sub) findByID(id uint64) (int, bool) { +func (s *sub) findByID(id uint64) (int, bool) { for i := range s.ids { if s.ids[i] == id { return i, true diff --git a/serv/admin.go b/serv/admin.go index ad5e1d7e..bc41437a 100644 --- a/serv/admin.go +++ b/serv/admin.go @@ -16,7 +16,7 @@ import ( func adminDeployHandler(s1 *HttpService) http.Handler { h := func(w http.ResponseWriter, r *http.Request) { var req DeployReq - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) if !s.isAdminSecret(r) { authFail(w) @@ -61,7 +61,7 @@ func adminDeployHandler(s1 *HttpService) http.Handler { // adminRollbackHandler handles the admin rollback endpoint func adminRollbackHandler(s1 *HttpService) http.Handler { h := func(w http.ResponseWriter, r *http.Request) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) if !s.isAdminSecret(r) { authFail(w) @@ -88,7 +88,7 @@ func adminRollbackHandler(s1 *HttpService) http.Handler { } // adminConfigHandler handles the checking of the admin secret endpoint -func (s *GraphjinService) isAdminSecret(r *http.Request) bool { +func (s *graphjinService) isAdminSecret(r *http.Request) bool { atomic.AddInt32(&s.adminCount, 1) defer atomic.StoreInt32(&s.adminCount, 0) diff --git a/serv/api.go b/serv/api.go index 82276f24..55c19c2f 100644 --- a/serv/api.go +++ b/serv/api.go @@ -71,7 +71,7 @@ const ( type HookFn func(*core.Result) -type GraphjinService struct { +type graphjinService struct { log *zap.SugaredLogger // logger zlog *zap.Logger // faster logger logLevel int // log level @@ -92,7 +92,7 @@ type GraphjinService struct { tracer trace.Tracer } -type Option func(*GraphjinService) error +type Option func(*graphjinService) error // NewGraphJinService a new service func NewGraphJinService(conf *Config, options ...Option) (*HttpService, error) { @@ -121,7 +121,7 @@ func NewGraphJinService(conf *Config, options ...Option) (*HttpService, error) { // OptionSetDB sets a new db client func OptionSetDB(db *sql.DB) Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.db = db return nil } @@ -129,7 +129,7 @@ func OptionSetDB(db *sql.DB) Option { // OptionSetHookFunc sets a function to be called on every request func OptionSetHookFunc(fn HookFn) Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.hook = fn return nil } @@ -137,7 +137,7 @@ func OptionSetHookFunc(fn HookFn) Option { // OptionSetNamespace sets service namespace func OptionSetNamespace(namespace string) Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.namespace = &namespace return nil } @@ -145,7 +145,7 @@ func OptionSetNamespace(namespace string) Option { // OptionSetFS sets service filesystem func OptionSetFS(fs core.FS) Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.fs = fs return nil } @@ -153,7 +153,7 @@ func OptionSetFS(fs core.FS) Option { // OptionSetZapLogger sets service structured logger func OptionSetZapLogger(zlog *zap.Logger) Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.zlog = zlog s.log = zlog.Sugar() return nil @@ -162,14 +162,14 @@ func OptionSetZapLogger(zlog *zap.Logger) Option { // OptionDeployActive caused the active config to be deployed on func OptionDeployActive() Option { - return func(s *GraphjinService) error { + return func(s *graphjinService) error { s.deployActive = true return nil } } // newGraphJinService creates a new service -func newGraphJinService(conf *Config, db *sql.DB, options ...Option) (*GraphjinService, error) { +func newGraphJinService(conf *Config, db *sql.DB, options ...Option) (*graphjinService, error) { var err error if conf == nil { conf = &Config{Core: Core{Debug: true}} @@ -179,7 +179,7 @@ func newGraphJinService(conf *Config, db *sql.DB, options ...Option) (*GraphjinS prod := conf.Serv.Production conf.Core.Production = prod - s := &GraphjinService{ + s := &graphjinService{ conf: conf, zlog: zlog, log: zlog.Sugar(), @@ -226,7 +226,7 @@ func newGraphJinService(conf *Config, db *sql.DB, options ...Option) (*GraphjinS } // normalStart starts the service in normal mode -func (s *GraphjinService) normalStart() error { +func (s *graphjinService) normalStart() error { opts := []core.Option{core.OptionSetFS(s.fs)} if s.namespace != nil { opts = append(opts, core.OptionSetNamespace(*s.namespace)) @@ -238,7 +238,7 @@ func (s *GraphjinService) normalStart() error { } // hotStart starts the service in hot-deploy mode -func (s *GraphjinService) hotStart() error { +func (s *graphjinService) hotStart() error { ab, err := fetchActiveBundle(s.db) if err != nil { if strings.Contains(err.Error(), "_graphjin.") { @@ -285,7 +285,7 @@ func (s *GraphjinService) hotStart() error { // Deploy a new configuration func (s *HttpService) Deploy(conf *Config, options ...Option) error { var err error - os := s.Load().(*GraphjinService) + os := s.Load().(*graphjinService) if conf == nil { return nil @@ -325,7 +325,7 @@ func (s *HttpService) attach(mux Mux, ns *string) error { return err } - s1 := s.Load().(*GraphjinService) + s1 := s.Load().(*graphjinService) ver := version dep := s1.conf.name @@ -393,24 +393,24 @@ func (s *HttpService) WebUI(routePrefix, gqlEndpoint string) http.Handler { // GetGraphJin fetching internal GraphJin core func (s *HttpService) GetGraphJin() *core.GraphJin { - s1 := s.Load().(*GraphjinService) + s1 := s.Load().(*graphjinService) return s1.gj } // GetDB fetching internal db client func (s *HttpService) GetDB() *sql.DB { - s1 := s.Load().(*GraphjinService) + s1 := s.Load().(*graphjinService) return s1.db } // Reload re-runs database discover and reinitializes service. func (s *HttpService) Reload() error { - s1 := s.Load().(*GraphjinService) + s1 := s.Load().(*graphjinService) return s1.gj.Reload() } // spanStart starts the tracer -func (s *GraphjinService) spanStart(c context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { +func (s *graphjinService) spanStart(c context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { return s.tracer.Start(c, name, opts...) } diff --git a/serv/db.go b/serv/db.go index ea05961f..3de28687 100644 --- a/serv/db.go +++ b/serv/db.go @@ -29,7 +29,7 @@ const ( logLevelDebug ) -type DBConf struct { +type dbConf struct { driverName string connString string } @@ -47,7 +47,7 @@ func newDB( fs core.FS, ) (*sql.DB, error) { var db *sql.DB - var dc *DBConf + var dc *dbConf var err error if cs := conf.DB.ConnString; cs != "" { @@ -100,7 +100,7 @@ func newDB( } // initPostgres initializes the postgres database -func initPostgres(conf *Config, openDB, useTelemetry bool, fs core.FS) (*DBConf, error) { +func initPostgres(conf *Config, openDB, useTelemetry bool, fs core.FS) (*dbConf, error) { confCopy := conf config, _ := pgx.ParseConfig(confCopy.DB.ConnString) if confCopy.DB.Host != "" { @@ -190,11 +190,11 @@ func initPostgres(conf *Config, openDB, useTelemetry bool, fs core.FS) (*DBConf, } } - return &DBConf{"pgx", stdlib.RegisterConnConfig(config)}, nil + return &dbConf{"pgx", stdlib.RegisterConnConfig(config)}, nil } // initMysql initializes the mysql database -func initMysql(conf *Config, openDB, useTelemetry bool, fs core.FS) (*DBConf, error) { +func initMysql(conf *Config, openDB, useTelemetry bool, fs core.FS) (*dbConf, error) { var connString string c := conf @@ -208,7 +208,7 @@ func initMysql(conf *Config, openDB, useTelemetry bool, fs core.FS) (*DBConf, er connString += c.DB.DBName } - return &DBConf{"mysql", connString}, nil + return &dbConf{"mysql", connString}, nil } // loadX509KeyPair loads a X509 key pair from a file system diff --git a/serv/deploy.go b/serv/deploy.go index ac2d93d7..ae7a26b5 100644 --- a/serv/deploy.go +++ b/serv/deploy.go @@ -24,7 +24,7 @@ type depResp struct { } // saveConfig saves the config to the database -func (s *GraphjinService) saveConfig(c context.Context, name, bundle string) (*depResp, error) { +func (s *graphjinService) saveConfig(c context.Context, name, bundle string) (*depResp, error) { var dres depResp zip, err := base64.StdEncoding.DecodeString(bundle) @@ -141,7 +141,7 @@ func (s *GraphjinService) saveConfig(c context.Context, name, bundle string) (*d } // rollbackConfig rolls back the config to the previous one -func (s *GraphjinService) rollbackConfig(c context.Context) (*depResp, error) { +func (s *graphjinService) rollbackConfig(c context.Context) (*depResp, error) { var dres depResp opt := &sql.TxOptions{Isolation: sql.LevelSerializable} @@ -268,7 +268,7 @@ func startHotDeployWatcher(s1 *HttpService) error { defer ticker.Stop() for range ticker.C { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) cf := s.conf.viper.ConfigFileUsed() cf = filepath.Join("/", filepath.Base(strings.TrimSuffix(cf, filepath.Ext(cf)))) diff --git a/serv/filewatch.go b/serv/filewatch.go index f6eca713..29e0f36e 100644 --- a/serv/filewatch.go +++ b/serv/filewatch.go @@ -60,7 +60,7 @@ func startConfigWatcher(s1 *HttpService) error { } for { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) select { case err := <-watcher.Errors: diff --git a/serv/health.go b/serv/health.go index 42dc863e..837df682 100644 --- a/serv/health.go +++ b/serv/health.go @@ -13,7 +13,7 @@ var healthyResponse = []byte("All's Well") // healthCheckHandler returns a handler that checks the health of the service func healthCheckHandler(s1 *HttpService) http.Handler { h := func(w http.ResponseWriter, r *http.Request) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) c, cancel := context.WithTimeout(r.Context(), s.conf.DB.PingTimeout) defer cancel() diff --git a/serv/http.go b/serv/http.go index 9f3fadab..66338b25 100644 --- a/serv/http.go +++ b/serv/http.go @@ -58,7 +58,7 @@ type errorResp struct { // apiV1Handler is the main handler for all API requests func apiV1Handler(s1 *HttpService, ns *string, h http.Handler, ah auth.HandlerFunc) http.Handler { var zlog *zap.Logger - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) if s.conf.Core.Debug { zlog = s.zlog @@ -116,7 +116,7 @@ func (s1 *HttpService) apiV1GraphQL(ns *string, ah auth.HandlerFunc) http.Handle var err error start := time.Now() - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) w.Header().Set("Content-Type", "application/json") @@ -216,7 +216,7 @@ func (s1 *HttpService) apiV1Rest(ns *string, ah auth.HandlerFunc) http.Handler { var err error start := time.Now() - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) w.Header().Set("Content-Type", "application/json") @@ -292,7 +292,7 @@ func (s1 *HttpService) apiV1Rest(ns *string, ah auth.HandlerFunc) http.Handler { } // responseHandler handles the response from the GraphQL API -func (s *GraphjinService) responseHandler(ct context.Context, +func (s *graphjinService) responseHandler(ct context.Context, w http.ResponseWriter, r *http.Request, start time.Time, @@ -335,7 +335,7 @@ func (s *GraphjinService) responseHandler(ct context.Context, } // reqLog logs the request details -func (s *GraphjinService) reqLog(res *core.Result, rc core.RequestConfig, resTimeMs int64, err error) { +func (s *graphjinService) reqLog(res *core.Result, rc core.RequestConfig, resTimeMs int64, err error) { var fields []zapcore.Field var sql string @@ -370,7 +370,7 @@ func (s *GraphjinService) reqLog(res *core.Result, rc core.RequestConfig, resTim } // setHeaderVars sets the header variables -func (s *GraphjinService) setHeaderVars(r *http.Request) map[string]interface{} { +func (s *graphjinService) setHeaderVars(r *http.Request) map[string]interface{} { vars := make(map[string]interface{}) for k, v := range s.conf.Core.HeaderVars { vars[k] = func() string { diff --git a/serv/init.go b/serv/init.go index 8b020af4..2de22bc9 100644 --- a/serv/init.go +++ b/serv/init.go @@ -11,7 +11,7 @@ import ( ) // initLogLevel initializes the log level -func initLogLevel(s *GraphjinService) { +func initLogLevel(s *graphjinService) { switch s.conf.LogLevel { case "debug": s.logLevel = logLevelDebug @@ -27,7 +27,7 @@ func initLogLevel(s *GraphjinService) { } // validateConf validates the configuration -func validateConf(s *GraphjinService) { +func validateConf(s *graphjinService) { var anonFound bool for _, r := range s.conf.Core.Roles { @@ -43,7 +43,7 @@ func validateConf(s *GraphjinService) { } // initFS initializes the file system -func (s *GraphjinService) initFS() error { +func (s *graphjinService) initFS() error { basePath, err := s.basePath() if err != nil { return err @@ -57,7 +57,7 @@ func (s *GraphjinService) initFS() error { } // initConfig initializes the configuration -func (s *GraphjinService) initConfig() error { +func (s *graphjinService) initConfig() error { c := s.conf c.dirty = true @@ -101,7 +101,7 @@ func (s *GraphjinService) initConfig() error { } // initDB initializes the database -func (s *GraphjinService) initDB() error { +func (s *graphjinService) initDB() error { var err error if s.db != nil { @@ -116,7 +116,7 @@ func (s *GraphjinService) initDB() error { } // basePath returns the base path -func (s *GraphjinService) basePath() (string, error) { +func (s *graphjinService) basePath() (string, error) { if s.conf.Serv.ConfigPath == "" { if cp, err := os.Getwd(); err == nil { return filepath.Join(cp, "config"), nil diff --git a/serv/internal/secrets/decrypt.go b/serv/internal/secrets/decrypt.go index ff6d7f89..6dcf3579 100644 --- a/serv/internal/secrets/decrypt.go +++ b/serv/internal/secrets/decrypt.go @@ -12,7 +12,7 @@ import ( "go.mozilla.org/sops/v3/keyservice" ) -type DecryptOpts struct { +type decryptOpts struct { Cipher sops.Cipher InputStore sops.Store OutputStore sops.Store @@ -23,7 +23,7 @@ type DecryptOpts struct { } // decrypt decrypts the file at the given path using options passed. -func decrypt(opts DecryptOpts, fs afero.Fs) (decryptedFile []byte, err error) { +func decrypt(opts decryptOpts, fs afero.Fs) (decryptedFile []byte, err error) { tree, err := LoadEncryptedFileWithBugFixes(common.GenericDecryptOpts{ Cipher: opts.Cipher, InputStore: opts.InputStore, diff --git a/serv/internal/secrets/edit.go b/serv/internal/secrets/edit.go index 01cbba7c..c67726cd 100644 --- a/serv/internal/secrets/edit.go +++ b/serv/internal/secrets/edit.go @@ -20,7 +20,7 @@ import ( "go.uber.org/zap" ) -type EditOpts struct { +type editOpts struct { log *zap.SugaredLogger Cipher sops.Cipher InputStore common.Store @@ -31,8 +31,8 @@ type EditOpts struct { ShowMasterKeys bool } -type EditExampleOpts struct { - EditOpts +type editExampleOpts struct { + editOpts UnencryptedSuffix string EncryptedSuffix string UnencryptedRegex string @@ -41,7 +41,7 @@ type EditExampleOpts struct { GroupThreshold int } -type RunEditorUntilOkOpts struct { +type runEditorUntilOkOpts struct { log *zap.SugaredLogger TmpFile *os.File OriginalHash []byte @@ -57,7 +57,7 @@ GJ_SECRET_KEY: graphjin_generic_secret_key GJ_AUTH_JWT_SECRET: jwt_auth_secret_key` // editExample edits the example file -func editExample(opts EditExampleOpts) ([]byte, error) { +func editExample(opts editExampleOpts) ([]byte, error) { branches, err := opts.InputStore.LoadPlainFile([]byte(fileBytes)) if err != nil { return nil, fmt.Errorf("error unmarshalling file: %s", err) @@ -85,11 +85,11 @@ func editExample(opts EditExampleOpts) ([]byte, error) { return nil, fmt.Errorf("error encrypting the data key with one or more master keys: %s", errs) } - return editTree(opts.EditOpts, &tree, dataKey) + return editTree(opts.editOpts, &tree, dataKey) } // edit edits the file at the given path using options passed. -func edit(opts EditOpts) ([]byte, error) { +func edit(opts editOpts) ([]byte, error) { // Load the file tree, err := common.LoadEncryptedFileWithBugFixes(common.GenericDecryptOpts{ Cipher: opts.Cipher, @@ -116,7 +116,7 @@ func edit(opts EditOpts) ([]byte, error) { } // editTree edits the tree using the options passed. -func editTree(opts EditOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) { +func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) { // Create temporary file for editing tmpdir, err := os.MkdirTemp("", "") if err != nil { @@ -154,7 +154,7 @@ func editTree(opts EditOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) { } // Let the user edit the file - err = runEditorUntilOk(RunEditorUntilOkOpts{ + err = runEditorUntilOk(runEditorUntilOkOpts{ log: opts.log, InputStore: opts.InputStore, OriginalHash: origHash, @@ -184,7 +184,7 @@ func editTree(opts EditOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) { } // runEditorUntilOk runs the editor until the file is saved and the hash is different -func runEditorUntilOk(opts RunEditorUntilOkOpts) error { +func runEditorUntilOk(opts runEditorUntilOkOpts) error { for { err := runEditor(opts.TmpFile.Name()) if err != nil { diff --git a/serv/internal/secrets/init.go b/serv/internal/secrets/init.go index 9c9b62da..6efdfd9a 100644 --- a/serv/internal/secrets/init.go +++ b/serv/internal/secrets/init.go @@ -18,7 +18,7 @@ func Init(filename string, fs afero.Fs) (map[string]string, error) { inputStore := common.DefaultStoreForPath(filename) ks := []keyservice.KeyServiceClient{keyservice.NewLocalClient()} - opts := DecryptOpts{ + opts := decryptOpts{ OutputStore: &dotenv.Store{}, InputStore: inputStore, InputPath: filename, diff --git a/serv/internal/secrets/rotate.go b/serv/internal/secrets/rotate.go index 8fb786eb..1a3a0512 100644 --- a/serv/internal/secrets/rotate.go +++ b/serv/internal/secrets/rotate.go @@ -12,7 +12,7 @@ import ( "go.uber.org/zap" ) -type RotateOpts struct { +type rotateOpts struct { log *zap.SugaredLogger Cipher sops.Cipher InputStore sops.Store @@ -25,7 +25,7 @@ type RotateOpts struct { } // rotate rotates the keys in the file at the given path using options passed. -func rotate(opts RotateOpts) ([]byte, error) { +func rotate(opts rotateOpts) ([]byte, error) { tree, err := common.LoadEncryptedFileWithBugFixes(common.GenericDecryptOpts{ Cipher: opts.Cipher, InputStore: opts.InputStore, diff --git a/serv/internal/secrets/run.go b/serv/internal/secrets/run.go index ab7ccfa6..8c8c24e0 100644 --- a/serv/internal/secrets/run.go +++ b/serv/internal/secrets/run.go @@ -72,7 +72,7 @@ func SecretsCmd(cmdName, fileName string, sa SecretArgs, args []string, log *zap rmKeys = allKeys } - output, err = rotate(RotateOpts{ + output, err = rotate(rotateOpts{ log: log, OutputStore: outputStore, InputStore: inputStore, @@ -96,7 +96,7 @@ func SecretsCmd(cmdName, fileName string, sa SecretArgs, args []string, log *zap _, statErr := os.Stat(fileName) fileExists := statErr == nil - opts := EditOpts{ + opts := editOpts{ log: log, OutputStore: outputStore, InputStore: inputStore, @@ -121,8 +121,8 @@ func SecretsCmd(cmdName, fileName string, sa SecretArgs, args []string, log *zap return fmt.Errorf("no key management provider defined") } - output, err = editExample(EditExampleOpts{ - EditOpts: opts, + output, err = editExample(editExampleOpts{ + editOpts: opts, UnencryptedSuffix: "", EncryptedSuffix: "", EncryptedRegex: "", diff --git a/serv/iplimiter.go b/serv/iplimiter.go index 06675e24..513a0466 100644 --- a/serv/iplimiter.go +++ b/serv/iplimiter.go @@ -36,7 +36,7 @@ func rateLimiter(s1 *HttpService, h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { var iph, ip string var err error - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) if s.conf.RateLimiter.IPHeader != "" { iph = r.Header.Get(s.conf.RateLimiter.IPHeader) diff --git a/serv/routes.go b/serv/routes.go index c5905a61..cebd8f57 100644 --- a/serv/routes.go +++ b/serv/routes.go @@ -19,7 +19,7 @@ type Mux interface { // routesHandler is the main handler for all routes func routesHandler(s1 *HttpService, mux Mux, ns *string) (http.Handler, error) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) // Healthcheck API mux.Handle(healthRoute, healthCheckHandler(s1)) diff --git a/serv/serv.go b/serv/serv.go index 6a349616..26870ae8 100644 --- a/serv/serv.go +++ b/serv/serv.go @@ -22,7 +22,7 @@ const ( // Initialize the watcher for the graphjin config file func initConfigWatcher(s1 *HttpService) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) if s.conf.Serv.Production { return } @@ -37,7 +37,7 @@ func initConfigWatcher(s1 *HttpService) { // Initialize the hot deploy watcher func initHotDeployWatcher(s1 *HttpService) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) go func() { err := startHotDeployWatcher(s1) if err != nil { @@ -48,7 +48,7 @@ func initHotDeployWatcher(s1 *HttpService) { // Start the HTTP server func startHTTP(s1 *HttpService) { - s := s1.Load().(*GraphjinService) + s := s1.Load().(*graphjinService) r := chi.NewRouter() routes, err := routesHandler(s1, r, s.namespace) diff --git a/serv/ws.go b/serv/ws.go index a01c2640..19e7e71d 100644 --- a/serv/ws.go +++ b/serv/ws.go @@ -73,7 +73,7 @@ type wsState struct { } // apiV1Ws handles the websocket connection -func (s *GraphjinService) apiV1Ws(w http.ResponseWriter, r *http.Request, ah auth.HandlerFunc) { +func (s *graphjinService) apiV1Ws(w http.ResponseWriter, r *http.Request, ah auth.HandlerFunc) { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { renderErr(w, err) @@ -127,7 +127,7 @@ type authHeaders struct { } // subSwitch handles the websocket message types -func (s *GraphjinService) subSwitch(wc *wsConn, req wsReq) (err error) { +func (s *graphjinService) subSwitch(wc *wsConn, req wsReq) (err error) { switch req.Type { case "connection_init": if err = setHeaders(req, wc.r); err != nil { @@ -194,7 +194,7 @@ func (s *GraphjinService) subSwitch(wc *wsConn, req wsReq) (err error) { } // waitForData waits for data from the subscription -func (s *GraphjinService) waitForData(wc *wsConn, st *wsState, useNext bool) { +func (s *graphjinService) waitForData(wc *wsConn, st *wsState, useNext bool) { var buf bytes.Buffer var ptype string