Skip to content

Commit

Permalink
Go lint comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianchifor committed Jul 5, 2020
1 parent a105861 commit 03ef3d3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func parseRequiredRequestParams(c *gin.Context, params ...string) (map[string]st
c.JSON(400, gin.H{
"error": fmt.Sprintf("Please provide '%s' as a querystring parameter", param),
})
return nil, errors.New(fmt.Sprintf("Failed to parse '%s' querystring parameter", param))
return nil, fmt.Errorf("Failed to parse '%s' querystring parameter", param)
}
if err := validateParam(c, paramValue); err != nil {
return nil, err
Expand Down Expand Up @@ -54,7 +54,7 @@ func parseExclusiveRequestParams(c *gin.Context, firstParam string, secondParam
c.JSON(400, gin.H{
"error": fmt.Sprintf("Please provide only one of '%s' or '%s' as a querystring parameter", firstParam, secondParam),
})
return "", "", errors.New(fmt.Sprintf("Failed to parse '%s, %s' querystring parameters", firstParam, secondParam))
return "", "", fmt.Errorf("Failed to parse '%s, %s' querystring parameters", firstParam, secondParam)
}
if err := validateParam(c, firstParamVal); err != nil {
return "", "", err
Expand Down
1 change: 1 addition & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
)

// Run HTTP server+router for API
func RunServer(port int) {
router := gin.Default()

Expand Down
6 changes: 6 additions & 0 deletions store/gcs_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
)

var (
// GCS bucket name
BucketName string
GoogBucket storage.BucketHandle
)

// Initialize GCS bucket client
func InitGoog() {
gcsClient, err := storage.NewClient(context.Background())
if err != nil {
Expand All @@ -26,6 +28,7 @@ func InitGoog() {
GoogBucket = *gcsClient.Bucket(BucketName)
}

// List objects in GCS bucket
func ListObjects(prefix string, delimiter string, limit int) ([]string, error) {
ctxTimeout, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
Expand Down Expand Up @@ -57,6 +60,7 @@ func ListObjects(prefix string, delimiter string, limit int) ([]string, error) {
return objects, nil
}

// Write data to GCS object, will be compressed with zstd
func WriteObject(object string, data []byte) error {
if len(object) == 0 {
return errors.New("store.WriteObject: object cannot be empty string")
Expand Down Expand Up @@ -85,6 +89,7 @@ func WriteObject(object string, data []byte) error {
return nil
}

// Read data from GCS object, will be automatically decompressed
func ReadObject(object string) ([]byte, error) {
if len(object) == 0 {
return nil, errors.New("store.ReadObject: object cannot be empty string")
Expand Down Expand Up @@ -112,6 +117,7 @@ func ReadObject(object string) ([]byte, error) {
return data, nil
}

// Delete GCS object
func DeleteObject(object string) error {
if len(object) == 0 {
return errors.New("store.DeleteObject: object cannot be empty string")
Expand Down
5 changes: 4 additions & 1 deletion utils/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
)

// Returns index if found, otherwise -1
// Linear search, returns first index where found, otherwise -1
func Search(list []string, a string) int {
for i, elem := range list {
if elem == a {
Expand All @@ -14,6 +14,7 @@ func Search(list []string, a string) int {
return -1
}

// Remove item from slice at index
func RemoveIndex(list []string, index int) []string {
list[index] = list[len(list)-1]
list[len(list)-1] = ""
Expand All @@ -22,6 +23,7 @@ func RemoveIndex(list []string, index int) []string {
return list
}

// Merge multiple maps into one; duplicate k-v in subsequent maps will override previous ones
func MergeMaps(maps ...map[string]string) map[string]string {
mergedMap := make(map[string]string)
for _, innerMap := range maps {
Expand All @@ -33,6 +35,7 @@ func MergeMaps(maps ...map[string]string) map[string]string {
return mergedMap
}

// Filter out 'bigbucket' and '/' from tables []string
func CleanupTables(tables []string) []string {
cleanTables := []string{}
for _, table := range tables {
Expand Down
1 change: 1 addition & 0 deletions utils/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/gin-gonic/gin"
)

// Create and run a new Gin HTTP server with graceful shutdown
func RunServer(port int, router *gin.Engine) {
done := make(chan bool, 1)
quit := make(chan os.Signal, 1)
Expand Down
2 changes: 2 additions & 0 deletions utils/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/adrianchifor/Bigbucket/store"
)

// Get object content as string[]
func GetState(object string) []string {
state := []string{}

Expand All @@ -20,6 +21,7 @@ func GetState(object string) []string {
return state
}

// Write string[] to object
func WriteState(object string, state []string) error {
buf := &bytes.Buffer{}
gob.NewEncoder(buf).Encode(state)
Expand Down
2 changes: 2 additions & 0 deletions worker/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
stopCleanerMutex = &sync.Mutex{}
)

// Run cleaner once or on an interval
func RunCleaner(interval int) {
done := make(chan bool, 1)
quit := make(chan os.Signal, 1)
Expand Down Expand Up @@ -57,6 +58,7 @@ func RunCleaner(interval int) {
log.Println("Cleaner process done")
}

// Run cleaner on HTTP POSTs
func RunCleanerHttp(port int) {
deleteJobPool := parallel.LargeJobPool()
defer deleteJobPool.Close()
Expand Down

0 comments on commit 03ef3d3

Please sign in to comment.