diff --git a/api/params.go b/api/params.go index 2427333..14b43f8 100644 --- a/api/params.go +++ b/api/params.go @@ -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 @@ -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 diff --git a/api/server.go b/api/server.go index 61aad5e..b87768b 100644 --- a/api/server.go +++ b/api/server.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" ) +// Run HTTP server+router for API func RunServer(port int) { router := gin.Default() diff --git a/store/gcs_bucket.go b/store/gcs_bucket.go index 0c8b15b..c38e690 100644 --- a/store/gcs_bucket.go +++ b/store/gcs_bucket.go @@ -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 { @@ -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() @@ -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") @@ -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") @@ -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") diff --git a/utils/functions.go b/utils/functions.go index 22c2601..52e4ebd 100644 --- a/utils/functions.go +++ b/utils/functions.go @@ -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 { @@ -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] = "" @@ -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 { @@ -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 { diff --git a/utils/server.go b/utils/server.go index 4a2cc6f..59c7627 100644 --- a/utils/server.go +++ b/utils/server.go @@ -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) diff --git a/utils/state.go b/utils/state.go index d44a789..f3f04ee 100644 --- a/utils/state.go +++ b/utils/state.go @@ -7,6 +7,7 @@ import ( "github.com/adrianchifor/Bigbucket/store" ) +// Get object content as string[] func GetState(object string) []string { state := []string{} @@ -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) diff --git a/worker/cleaner.go b/worker/cleaner.go index b089a85..49ba3ba 100644 --- a/worker/cleaner.go +++ b/worker/cleaner.go @@ -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) @@ -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()