Skip to content

Commit 43bb5fc

Browse files
lint, vet and docs
1 parent eb42689 commit 43bb5fc

24 files changed

+144
-110
lines changed

Diff for: abtest.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import (
88
"time"
99
)
1010

11+
// ABTestType is the type of the AB testing: model or static
1112
type ABTestType int
1213

14+
// Static is used to do AB testing for static assets (images, js, css, ...)
1315
func (ABTestType) Static() ABTestType {
1416
return 1
1517
}
1618

19+
// Model is used to do AB testing for model values coming from database
1720
func (ABTestType) Model() ABTestType {
1821
return 2
1922
}

Diff for: abtest_value.go

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
)
88

9+
// ABTestValue is a model to represent a possible value of an AB test
910
type ABTestValue struct {
1011
Model
1112
ABTest ABTest
@@ -20,17 +21,21 @@ func (a *ABTestValue) String() string {
2021
return a.Value
2122
}
2223

24+
// ClickThroughRate returns the rate of click through of this value
2325
func (a *ABTestValue) ClickThroughRate() float64 {
2426
if a.Impressions == 0 {
2527
return 0.0
2628
}
2729
return float64(a.Clicks) / float64(a.Impressions) * 100
2830
}
2931

32+
// ClickThroughRate__Form__List shows the click through rate in form
33+
// and list views
3034
func (a ABTestValue) ClickThroughRate__Form__List() string {
3135
return fmt.Sprintf("<b>%.2f%%</b>", a.ClickThroughRate())
3236
}
3337

38+
// Preview__Form__List shows a preview of the AB test's value
3439
func (a ABTestValue) Preview__Form__List() string {
3540
// Check if the value is a path to a file
3641
if strings.HasPrefix(a.Value, "/") {
@@ -48,6 +53,7 @@ func (a ABTestValue) Preview__Form__List() string {
4853
return a.Value
4954
}
5055

56+
// HideInDashboard to hide it from dashboard
5157
func (ABTestValue) HideInDashboard() bool {
5258
return true
5359
}

Diff for: auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var bcryptDiff = 12
2727
// cachedSessions is variable for keeping active sessions
2828
var cachedSessions map[string]Session
2929

30-
// invalidAttemps keeps track of invalid password attemps
30+
// invalidAttemps keeps track of invalid password attempts
3131
// per IP address
3232
var invalidAttempts = map[string]int{}
3333

Diff for: d_api_add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func dAPIAddHandler(w http.ResponseWriter, r *http.Request, s *Session) {
8181
for i := range q {
8282
// Build args place holder
8383
argsPlaceHolder := []string{}
84-
for _ = range args[i] {
84+
for range args[i] {
8585
argsPlaceHolder = append(argsPlaceHolder, "?")
8686
}
8787

Diff for: d_api_helper.go

+40-10
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,26 @@ func getQueryOperator(r *http.Request, v string, tableName string) string {
192192
if strings.HasSuffix(v, "__gt") {
193193
if n {
194194
return strings.TrimSuffix(v, "__gt") + "` <= ?"
195-
} else {
196-
return strings.TrimSuffix(v, "__gt") + "` > ?"
197195
}
196+
return strings.TrimSuffix(v, "__gt") + "` > ?"
198197
}
199198
if strings.HasSuffix(v, "__gte") {
200199
if n {
201200
return strings.TrimSuffix(v, "__gte") + "` < ?"
202-
} else {
203-
return strings.TrimSuffix(v, "__gte") + "` >= ?"
204201
}
202+
return strings.TrimSuffix(v, "__gte") + "` >= ?"
205203
}
206204
if strings.HasSuffix(v, "__lt") {
207205
if n {
208206
return strings.TrimSuffix(v, "__lt") + "` >= ?"
209-
} else {
210-
return strings.TrimSuffix(v, "__lt") + "` < ?"
211207
}
208+
return strings.TrimSuffix(v, "__lt") + "` < ?"
212209
}
213210
if strings.HasSuffix(v, "__lte") {
214211
if n {
215212
return strings.TrimSuffix(v, "__lte") + "` > ?"
216-
} else {
217-
return strings.TrimSuffix(v, "__lte") + "` <= ?"
218213
}
214+
return strings.TrimSuffix(v, "__lte") + "` <= ?"
219215
}
220216
if strings.HasSuffix(v, "__in") {
221217
return strings.TrimSuffix(v, "__in") + nTerm + "` IN (?)"
@@ -278,9 +274,8 @@ func getQueryArg(k, v string) []interface{} {
278274
if strings.HasSuffix(k, "__is") {
279275
if strings.ToUpper(v) == "NULL" {
280276
return []interface{}{interface{}(nil)}
281-
} else {
282-
return []interface{}{v}
283277
}
278+
return []interface{}{v}
284279
}
285280
if strings.HasSuffix(k, "__contains") {
286281
return []interface{}{"%" + v + "%"}
@@ -667,102 +662,137 @@ func returnDAPIJSON(w http.ResponseWriter, r *http.Request, a map[string]interfa
667662
return nil
668663
}
669664

665+
// APILogReader is an interface for models to control loggin their read function in dAPI
670666
type APILogReader interface {
671667
APILogRead(*http.Request) bool
672668
}
673669

670+
// APILogEditor is an interface for models to control loggin their edit function in dAPI
674671
type APILogEditor interface {
675672
APILogEdit(*http.Request) bool
676673
}
677674

675+
// APILogAdder is an interface for models to control loggin their add function in dAPI
678676
type APILogAdder interface {
679677
APILogAdd(*http.Request) bool
680678
}
681679

680+
// APILogDeleter is an interface for models to control loggin their delete function in dAPI
682681
type APILogDeleter interface {
683682
APILogDelete(*http.Request) bool
684683
}
685684

685+
// APILogSchemer is an interface for models to control loggin their schema function in dAPI
686686
type APILogSchemer interface {
687687
APILogSchema(*http.Request) bool
688688
}
689689

690+
// APIPublicReader is an interface for models to control public access to read function in dAPI
690691
type APIPublicReader interface {
691692
APIPublicRead(*http.Request) bool
692693
}
693694

695+
// APIPublicEditor is an interface for models to control public access to read function in dAPI
694696
type APIPublicEditor interface {
695697
APIPublicEdit(*http.Request) bool
696698
}
697699

700+
// APIPublicAdder is an interface for models to control public access to add function in dAPI
698701
type APIPublicAdder interface {
699702
APIPublicAdd(*http.Request) bool
700703
}
701704

705+
// APIPublicDeleter is an interface for models to control public access to delete function in dAPI
702706
type APIPublicDeleter interface {
703707
APIPublicDelete(*http.Request) bool
704708
}
705709

710+
// APIPublicSchemer is an interface for models to control public access to schema function in dAPI
706711
type APIPublicSchemer interface {
707712
APIPublicSchema(*http.Request) bool
708713
}
709714

715+
// APIDisabledReader is an interface for models to disable access to read function in dAPI
710716
type APIDisabledReader interface {
711717
APIDisabledRead(*http.Request) bool
712718
}
713719

720+
// APIDisabledEditor is an interface for models to disable access to edit function in dAPI
714721
type APIDisabledEditor interface {
715722
APIDisabledEdit(*http.Request) bool
716723
}
717724

725+
// APIDisabledAdder is an interface for models to disable access to add function in dAPI
718726
type APIDisabledAdder interface {
719727
APIDisabledAdd(*http.Request) bool
720728
}
721729

730+
// APIDisabledDeleter is an interface for models to disable access to delete function in dAPI
722731
type APIDisabledDeleter interface {
723732
APIDisabledDelete(*http.Request) bool
724733
}
725734

735+
// APIDisabledSchemer is an interface for models to disable access to schema function in dAPI
726736
type APIDisabledSchemer interface {
727737
APIDisabledSchema(*http.Request) bool
728738
}
729739

740+
// APIPreQueryReader is an interface for models to run before processing read function in dAPI.
741+
// Returning false stops the rest of the process from happening
730742
type APIPreQueryReader interface {
731743
APIPreQueryRead(http.ResponseWriter, *http.Request) bool
732744
}
733745

746+
// APIPostQueryReader is an interface for models to run after processing read function in dAPI
747+
// and before returning the results. Returning false stops the rest of the process from happening
734748
type APIPostQueryReader interface {
735749
APIPostQueryRead(http.ResponseWriter, *http.Request, map[string]interface{}) bool
736750
}
737751

752+
// APIPreQueryAdder is an interface for models to run before processing add function in dAPI.
753+
// Returning false stops the rest of the process from happening
738754
type APIPreQueryAdder interface {
739755
APIPreQueryAdd(http.ResponseWriter, *http.Request) bool
740756
}
741757

758+
// APIPostQueryAdder is an interface for models to run after processing add function in dAPI
759+
// and before returning the results. Returning false stops the rest of the process from happening
742760
type APIPostQueryAdder interface {
743761
APIPostQueryAdd(http.ResponseWriter, *http.Request, map[string]interface{}) bool
744762
}
745763

764+
// APIPreQueryEditor is an interface for models to run before processing edit function in dAPI.
765+
// Returning false stops the rest of the process from happening
746766
type APIPreQueryEditor interface {
747767
APIPreQueryEdit(http.ResponseWriter, *http.Request) bool
748768
}
749769

770+
// APIPostQueryEditor is an interface for models to run after processing edit function in dAPI
771+
// and before returning the results. Returning false stops the rest of the process from happening
750772
type APIPostQueryEditor interface {
751773
APIPostQueryEdit(http.ResponseWriter, *http.Request, map[string]interface{}) bool
752774
}
753775

776+
// APIPreQueryDeleter is an interface for models to run before processing delete function in dAPI.
777+
// Returning false stops the rest of the process from happening
754778
type APIPreQueryDeleter interface {
755779
APIPreQueryDelete(http.ResponseWriter, *http.Request) bool
756780
}
757781

782+
// APIPostQueryDeleter is an interface for models to run after processing delete function in dAPI
783+
// and before returning the results. Returning false stops the rest of the process from happening
758784
type APIPostQueryDeleter interface {
759785
APIPostQueryDelete(http.ResponseWriter, *http.Request, map[string]interface{}) bool
760786
}
761787

788+
// APIPreQuerySchemer is an interface for models to run before processing schema function in dAPI.
789+
// Returning false stops the rest of the process from happening
762790
type APIPreQuerySchemer interface {
763791
APIPreQuerySchema(http.ResponseWriter, *http.Request) bool
764792
}
765793

794+
// APIPostQuerySchemer is an interface for models to run after processing schema function in dAPI
795+
// and before returning the results. Returning false stops the rest of the process from happening
766796
type APIPostQuerySchemer interface {
767797
APIPostQuerySchema(http.ResponseWriter, *http.Request, map[string]interface{}) bool
768798
}

Diff for: d_api_schema.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package uadmin
22

33
import (
44
"encoding/json"
5-
"github.com/jinzhu/gorm"
65
"net/http"
76
"strings"
7+
8+
"github.com/jinzhu/gorm"
89
)
910

1011
func dAPISchemaHandler(w http.ResponseWriter, r *http.Request, s *Session) {
@@ -45,10 +46,12 @@ func dAPISchemaHandler(w http.ResponseWriter, r *http.Request, s *Session) {
4546

4647
// Get Language
4748
lang := r.URL.Query().Get("language")
48-
if langC, err := r.Cookie("language"); err != nil || (langC != nil && langC.Value == "") {
49-
lang = GetDefaultLanguage().Code
50-
} else {
51-
lang = langC.Value
49+
if lang == "" {
50+
if langC, err := r.Cookie("language"); err != nil || (langC != nil && langC.Value == "") {
51+
lang = GetDefaultLanguage().Code
52+
} else {
53+
lang = langC.Value
54+
}
5255
}
5356

5457
// Translation

0 commit comments

Comments
 (0)