diff --git a/README.md b/README.md index 7edc1bc..4d2d901 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Hermes   -<img width="1173" alt="Screenshot 2023-06-03 at 1 55 31 PM" src="https://github.com/realTristan/Hermes/assets/75189508/f884f643-00af-405d-900d-a636d119cf74"> +# Hermes   +<img width="1173" alt="Screenshot 2023-06-03 at 1 55 31 PM" src="https://github.com/realTristan/hermes/assets/75189508/f884f643-00af-405d-900d-a636d119cf74"> ## Hermes Go Direct access to the hermes cache/nocache functions. ``` -go get github.com/realTristan/Hermes +go get github.com/realTristan/hermes ``` ## Hermes Cloud @@ -30,15 +30,15 @@ import ( "fmt" "time" - Hermes "github.com/realTristan/Hermes/nocache" + hermes "github.com/realTristan/hermes/nocache" ) func main() { // Initialize the full-text cache - var ft, _ = Hermes.InitWithJson("data.json") + var ft, _ = hermes.InitWithJson("data.json") // Search for a word in the cache - var res, _ = ft.Search(Hermes.SearchParams{ + var res, _ = ft.Search(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, @@ -59,7 +59,7 @@ Query: Computer, Limit: 100, Strict: True => 12.102µs ``` ### data.json -Used with Hermes.InitWithJson() +Used with hermes.InitWithJson() ```json [ { @@ -82,14 +82,14 @@ package main import ( "fmt" "time" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func main() { // Initialize the cache - cache := Hermes.InitCache() + cache := hermes.InitCache() - // MaxLength: 10, MaxBytes: -1 (no limit), MinWordLength: 3 + // MaxSize: 10, MaxBytes: -1 (no limit), MinWordLength: 3 cache.FTInit(10, -1, 3) // Set the value in the cache @@ -99,7 +99,7 @@ func main() { }) // Search for a word in the cache and print the result - result, err := cache.Search(Hermes.SearchParams{ + result, err := cache.Search(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, @@ -143,17 +143,17 @@ Coming Soon ```go import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Socket "github.com/realTristan/Hermes/cloud/socket" + hermes "github.com/realTristan/hermes" + socket "github.com/realTristan/hermes/cloud/socket" ) func main() { // Cache and fiber app - cache := Hermes.InitCache() + cache := hermes.InitCache() app := fiber.New() // Set the router - Socket.SetRouter(app, cache) + socket.SetRouter(app, cache) // Listen on port 3000 app.Listen(":3000") @@ -163,7 +163,7 @@ func main() { # Websocket API ## Cache -### [cache.set](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/set.go) +### [cache.set](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/set.go) #### About ``` @@ -189,7 +189,7 @@ Set a value in the cache with the corresponding key. } ``` -### [cache.delete](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/delete.go) +### [cache.delete](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/delete.go) #### About ``` @@ -212,7 +212,7 @@ Delete the provided key, and the data correlated to it from the cache. } ``` -### [cache.get](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/get.go) +### [cache.get](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/get.go) #### About ``` @@ -235,7 +235,7 @@ Get data from the cache using a key. } ``` -### [cache.keys](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/keys.go) +### [cache.keys](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/keys.go) #### About ``` @@ -257,7 +257,7 @@ Get all of the keys in the cache. } ``` -### [cache.values](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/values.go) +### [cache.values](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/values.go) #### About ``` @@ -279,7 +279,7 @@ Get all of the values in the cache. } ``` -### [cache.length](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/length.go) +### [cache.length](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/length.go) #### About ``` @@ -301,7 +301,7 @@ Get the amount of keys stored in the cache. } ``` -### [cache.clean](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/clean.go) +### [cache.clean](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/clean.go) #### About ``` @@ -323,7 +323,7 @@ Clean all the data in the cache, and full-text storage. } ``` -### [cache.info](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/info.go) +### [cache.info](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/info.go) #### About ``` @@ -345,7 +345,7 @@ Get the cache and full-text storage statistics. } ``` -### [cache.exists](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/exists.go) +### [cache.exists](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/exists.go) #### About ``` @@ -370,7 +370,7 @@ Get whether a key exists in the cache. ## Full-Text -### [ft.init](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/init.go) +### [ft.init](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/init.go) #### About ``` @@ -382,7 +382,7 @@ Intialize the full text cache. { "function": "ft.init", "maxbytes": -1, - "maxlength": -1, + "maxsize": -1, "minwordlength": 3 } ``` @@ -395,7 +395,7 @@ Intialize the full text cache. } ``` -### [ft.clean](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/clean.go) +### [ft.clean](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/clean.go) #### About ``` @@ -417,7 +417,7 @@ Clean all of the data in the full-text storage. } ``` -### [ft.search](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/search.go) +### [ft.search](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/search.go) #### About ``` @@ -442,7 +442,7 @@ Search for a query in the full-text storage. } ``` -### [ft.search.oneword](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/search.go) +### [ft.search.oneword](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/search.go) #### About ``` @@ -467,7 +467,7 @@ Search for a single word in the full-text storage. } ``` -### [ft.search.values](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/search.go) +### [ft.search.values](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/search.go) #### About ``` @@ -494,7 +494,7 @@ Search in the cache data values. (Slower) } ``` -### [ft.search.withkey](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/search.go) +### [ft.search.withkey](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/search.go) #### About ``` @@ -519,7 +519,7 @@ Search in the cache data values for a specific key. } ``` -### [ft.maxbytes.set](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.maxbytes.set](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -542,7 +542,7 @@ Set the maximum full-text storage size in bytes. } ``` -### [ft.maxlength.set](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.maxsize.set](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -552,8 +552,8 @@ Set the maximum full-text storage words allowed to be stored. #### Example Request ```go { - "function": "ft.maxlength.set", - "maxlength": -1 + "function": "ft.maxsize.set", + "maxsize": -1 } ``` @@ -565,7 +565,7 @@ Set the maximum full-text storage words allowed to be stored. } ``` -### [ft.storage](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.storage](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -587,7 +587,7 @@ Get the current full-text storage. } ``` -### [ft.storage.size](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.storage.size](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -609,7 +609,7 @@ Get the current full-text storage size in bytes. } ``` -### [ft.storage.length](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.storage.length](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -631,7 +631,7 @@ Get the current full-text storage length. } ``` -### [ft.isinitialized](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/fulltext.go) +### [ft.isinitialized](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/fulltext.go) #### About ``` @@ -653,7 +653,7 @@ Get whether the full-text storage has been initialized. } ``` -### [ft.indices.sequence](https://github.com/realTristan/Hermes/blob/master/cloud/socket/handlers/indices.go) +### [ft.indices.sequence](https://github.com/realTristan/hermes/blob/master/cloud/socket/handlers/indices.go) #### About ``` diff --git a/cloud/api/handlers/clean.go b/cloud/api/handlers/clean.go index fda0dd9..8df6143 100644 --- a/cloud/api/handlers/clean.go +++ b/cloud/api/handlers/clean.go @@ -2,34 +2,34 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Clean is a function that returns a fiber context handler function for cleaning the regular cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that cleans the regular cache and returns a success message. -func Clean(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Clean(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { c.Clean() - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } // FTClean is a function that returns a fiber context handler function for cleaning the full-text cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that cleans the full-text cache and returns a success message or an error message if the cleaning fails. -func FTClean(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTClean(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if err := c.FTClean(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/delete.go b/cloud/api/handlers/delete.go index 47cf8d0..7449824 100644 --- a/cloud/api/handlers/delete.go +++ b/cloud/api/handlers/delete.go @@ -2,26 +2,26 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Delete is a handler function that returns a fiber context handler function for deleting a key from the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that deletes a key from the cache and returns a success message or an error message if the key is not provided. -func Delete(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Delete(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the key from the query var key string if key = ctx.Query("key"); len(key) == 0 { - return ctx.Send(Utils.Error("key not provided")) + return ctx.Send(utils.Error("key not provided")) } // Delete the key from the cache c.Delete(key) - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/exists.go b/cloud/api/handlers/exists.go index 9a9f031..de062ba 100644 --- a/cloud/api/handlers/exists.go +++ b/cloud/api/handlers/exists.go @@ -2,25 +2,25 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Exists is a handler function that returns a fiber context handler function for checking if a key exists in the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that checks if a key exists in the cache and returns a success message with a boolean value indicating whether the key exists or an error message if the key is not provided. -func Exists(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Exists(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the key from the query var key string if key = ctx.Query("key"); len(key) == 0 { - return ctx.Send(Utils.Error("key not provided")) + return ctx.Send(utils.Error("key not provided")) } // Return whether the key exists - return ctx.Send(Utils.Success(c.Exists(key))) + return ctx.Send(utils.Success(c.Exists(key))) } } diff --git a/cloud/api/handlers/fulltext.go b/cloud/api/handlers/fulltext.go index e2ee110..173b840 100644 --- a/cloud/api/handlers/fulltext.go +++ b/cloud/api/handlers/fulltext.go @@ -4,78 +4,78 @@ import ( "encoding/json" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // FTIsInitialized is a handler function that returns a fiber context handler function for checking if the full-text search is initialized. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that checks if the full-text search is initialized and returns a success message with a boolean value indicating whether it is initialized. -func FTIsInitialized(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTIsInitialized(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { - return ctx.Send(Utils.Success(c.FTIsInitialized())) + return ctx.Send(utils.Success(c.FTIsInitialized())) } } // FTSetMaxBytes is a handler function that returns a fiber context handler function for setting the maximum number of bytes for full-text search. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that sets the maximum number of bytes for full-text search and returns a success message or an error message if the value is not provided or if the setting fails. -func FTSetMaxBytes(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTSetMaxBytes(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the value from the query var value int - if err := Utils.GetMaxBytesParam(ctx, &value); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxBytesParam(ctx, &value); err != nil { + return ctx.Send(utils.Error(err)) } // Set the max bytes if err := c.FTSetMaxBytes(value); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } -// FTSetMaxLength is a handler function that returns a fiber context handler function for setting the maximum length for full-text search. +// FTSetMaxSize is a handler function that returns a fiber context handler function for setting the maximum length for full-text search. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that sets the maximum length for full-text search and returns a success message or an error message if the value is not provided or if the setting fails. -func FTSetMaxLength(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTSetMaxSize(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the value from the query var value int - if err := Utils.GetMaxLengthParam(ctx, &value); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxSizeParam(ctx, &value); err != nil { + return ctx.Send(utils.Error(err)) } // Set the max length - if err := c.FTSetMaxLength(value); err != nil { - return ctx.Send(Utils.Error(err)) + if err := c.FTSetMaxSize(value); err != nil { + return ctx.Send(utils.Error(err)) } - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } // FTStorage is a handler function that returns a fiber context handler function for getting the full-text storage. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets the full-text storage and returns a JSON-encoded string of the data or an error message if the retrieval or encoding fails. -func FTStorage(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTStorage(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if data, err := c.FTStorage(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else if data, err := json.Marshal(data); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } @@ -84,56 +84,56 @@ func FTStorage(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // FTStorageLength is a handler function that returns a fiber context handler function for getting the length of the full-text storage. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets the length of the full-text storage and returns a success message with the length or an error message if the retrieval fails. -func FTStorageLength(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTStorageLength(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if length, err := c.FTStorageLength(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { - return ctx.Send(Utils.Success(length)) + return ctx.Send(utils.Success(length)) } } } // FTStorageSize is a handler function that returns a fiber context handler function for getting the size of the full-text storage. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets the size of the full-text storage and returns a success message with the size or an error message if the retrieval fails. -func FTStorageSize(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTStorageSize(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if size, err := c.FTStorageSize(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { - return ctx.Send(Utils.Success(size)) + return ctx.Send(utils.Success(size)) } } } // FTSetMinWordLength is a handler function that returns a fiber context handler function for setting the minimum word length for full-text search. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that sets the minimum word length for full-text search and returns a success message or an error message if the value is not provided or if the setting fails. -func FTSetMinWordLength(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTSetMinWordLength(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the min word length from the query var minWordLength int - if err := Utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { + return ctx.Send(utils.Error(err)) } // Update the min word length if err := c.FTSetMinWordLength(minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } // Return null - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/get.go b/cloud/api/handlers/get.go index 815e40e..4e71c21 100644 --- a/cloud/api/handlers/get.go +++ b/cloud/api/handlers/get.go @@ -4,27 +4,27 @@ import ( "encoding/json" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Get is a handler function that returns a fiber context handler function for getting a value from the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets a value from the cache using a key provided in the query string and returns a JSON-encoded string of the value or an error message if the key is not provided or if the retrieval or encoding fails. -func Get(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Get(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { // Get the key from the query var key string if key = ctx.Query("key"); len(key) == 0 { - return ctx.Send(Utils.Error("key not provided")) + return ctx.Send(utils.Error("key not provided")) } // Get the value from the cache if data, err := json.Marshal(c.Get(key)); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } @@ -33,11 +33,11 @@ func Get(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // GetAll is a handler function that returns a fiber context handler function for getting all the data from the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets all the data from the cache and returns a success message with a JSON-encoded string of the data or an error message if the retrieval or encoding fails. -func GetAll(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func GetAll(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { return nil } diff --git a/cloud/api/handlers/indices.go b/cloud/api/handlers/indices.go index af910ff..81a8500 100644 --- a/cloud/api/handlers/indices.go +++ b/cloud/api/handlers/indices.go @@ -2,19 +2,19 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // FTSequenceIndices is a handler function that returns a fiber context handler function for sequencing the full-text storage indices. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that sequences the full-text storage indices and returns a success message or an error message if the sequencing fails. -func FTSequenceIndices(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTSequenceIndices(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { c.FTSequenceIndices() - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/info.go b/cloud/api/handlers/info.go index 36213dc..3b81129 100644 --- a/cloud/api/handlers/info.go +++ b/cloud/api/handlers/info.go @@ -2,24 +2,24 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Info is a function that returns information about the cache. // // Parameters: -// - c: A pointer to a Hermes.Cache struct representing the cache to get information from. +// - c: A pointer to a hermes.Cache struct representing the cache to get information from. // // Returns: // - A function that takes a pointer to a fiber.Ctx struct and returns an error. // The function returns information about the cache. -func Info(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Info(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if info, err := c.Info(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { - return ctx.Send(Utils.Success(info)) + return ctx.Send(utils.Success(info)) } } } @@ -27,17 +27,17 @@ func Info(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // InfoForTesting is a function that returns information about the cache for testing purposes. // // Parameters: -// - c: A pointer to a Hermes.Cache struct representing the cache to get information from. +// - c: A pointer to a hermes.Cache struct representing the cache to get information from. // // Returns: // - A function that takes a pointer to a fiber.Ctx struct and returns an error. // The function returns information about the cache for testing purposes. -func InfoForTesting(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func InfoForTesting(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if info, err := c.InfoForTesting(); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { - return ctx.Send(Utils.Success(info)) + return ctx.Send(utils.Success(info)) } } } diff --git a/cloud/api/handlers/init.go b/cloud/api/handlers/init.go index 409fcd7..08b844e 100644 --- a/cloud/api/handlers/init.go +++ b/cloud/api/handlers/init.go @@ -2,88 +2,88 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // FTInit is a handler function that returns a fiber context handler function for initializing the full-text search cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that initializes the full-text search cache using the max length, max bytes, and min word length parameters provided in the query string and returns a success message or an error message if the parameters are not provided or if the initialization fails. -func FTInit(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTInit(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( - maxLength int + maxSize int maxBytes int minWordLength int ) // Get the max length parameter - if err := Utils.GetMaxLengthParam(ctx, &maxLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxSizeParam(ctx, &maxSize); err != nil { + return ctx.Send(utils.Error(err)) } // Get the max bytes parameter - if err := Utils.GetMaxBytesParam(ctx, &maxBytes); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxBytesParam(ctx, &maxBytes); err != nil { + return ctx.Send(utils.Error(err)) } // Get the min word length parameter - if err := Utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { + return ctx.Send(utils.Error(err)) } // Initialize the full-text cache - if err := c.FTInit(maxLength, maxBytes, minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := c.FTInit(maxSize, maxBytes, minWordLength); err != nil { + return ctx.Send(utils.Error(err)) } - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } // FTInitJson is a handler function that returns a fiber context handler function for initializing the full-text search cache with a JSON object. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that initializes the full-text search cache using a JSON object, max length, max bytes, and min word length parameters provided in the query string and returns a success message or an error message if the parameters are not provided or if the initialization fails. -func FTInitJson(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func FTInitJson(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( - maxLength int + maxSize int maxBytes int minWordLength int json map[string]map[string]interface{} ) // Get the max length from the query - if err := Utils.GetMaxLengthParam(ctx, &maxLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxSizeParam(ctx, &maxSize); err != nil { + return ctx.Send(utils.Error(err)) } // Get the max bytes from the query - if err := Utils.GetMaxBytesParam(ctx, &maxBytes); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMaxBytesParam(ctx, &maxBytes); err != nil { + return ctx.Send(utils.Error(err)) } // Get the min word length from the query - if err := Utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetMinWordLengthParam(ctx, &minWordLength); err != nil { + return ctx.Send(utils.Error(err)) } // Get the JSON from the query - if err := Utils.GetJSONParam(ctx, &json); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetJSONParam(ctx, &json); err != nil { + return ctx.Send(utils.Error(err)) } // Initialize the full-text cache - if err := c.FTInitWithMap(json, maxLength, maxBytes, minWordLength); err != nil { - return ctx.Send(Utils.Error(err)) + if err := c.FTInitWithMap(json, maxSize, maxBytes, minWordLength); err != nil { + return ctx.Send(utils.Error(err)) } // Return success message - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/keys.go b/cloud/api/handlers/keys.go index edc5374..2566f9c 100644 --- a/cloud/api/handlers/keys.go +++ b/cloud/api/handlers/keys.go @@ -4,20 +4,20 @@ import ( "encoding/json" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Keys is a handler function that returns a fiber context handler function for getting all the keys from the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets all the keys from the cache and returns a JSON-encoded string of the keys or an error message if the retrieval or encoding fails. -func Keys(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Keys(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if keys, err := json.Marshal(c.Keys()); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(keys) } diff --git a/cloud/api/handlers/length.go b/cloud/api/handlers/length.go index 16c72ce..4ce11b6 100644 --- a/cloud/api/handlers/length.go +++ b/cloud/api/handlers/length.go @@ -2,18 +2,18 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Length is a handler function that returns a fiber context handler function for getting the length of the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets the length of the cache and returns a success message with the length or an error message if the retrieval fails. -func Length(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Length(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { - return ctx.Send(Utils.Success(c.Length())) + return ctx.Send(utils.Success(c.Length())) } } diff --git a/cloud/api/handlers/search.go b/cloud/api/handlers/search.go index 356a1b3..39c25b2 100644 --- a/cloud/api/handlers/search.go +++ b/cloud/api/handlers/search.go @@ -4,17 +4,17 @@ import ( "encoding/json" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Search is a handler function that returns a fiber context handler function for searching the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that searches the cache using the query, limit, strict, and schema parameters provided in the query string and returns a JSON-encoded string of the search results or an error message if the search fails or if the parameters are not provided. -func Search(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Search(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( strict bool @@ -24,28 +24,28 @@ func Search(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // Get the query from the url params if query = ctx.Query("query"); len(query) == 0 { - return ctx.Send(Utils.Error("query not provided")) + return ctx.Send(utils.Error("query not provided")) } // Get the limit from the url params - if err := Utils.GetLimitParam(ctx, &limit); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetLimitParam(ctx, &limit); err != nil { + return ctx.Send(utils.Error(err)) } // Get the strict from the url params - if err := Utils.GetStrictParam(ctx, &strict); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetStrictParam(ctx, &strict); err != nil { + return ctx.Send(utils.Error(err)) } // Search for the query - if res, err := c.Search(Hermes.SearchParams{ + if res, err := c.Search(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, }); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else if data, err := json.Marshal(res); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } @@ -54,11 +54,11 @@ func Search(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // SearchOneWord is a handler function that returns a fiber context handler function for searching the cache for a single word. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that searches the cache for a single word using the query, limit, and strict parameters provided in the query string and returns a JSON-encoded string of the search results or an error message if the search fails or if the parameters are not provided. -func SearchOneWord(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func SearchOneWord(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( strict bool @@ -68,28 +68,28 @@ func SearchOneWord(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // Get the query from the url params if query = ctx.Query("query"); len(query) == 0 { - return ctx.Send(Utils.Error("invalid query")) + return ctx.Send(utils.Error("invalid query")) } // Get the limit from the url params - if err := Utils.GetLimitParam(ctx, &limit); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetLimitParam(ctx, &limit); err != nil { + return ctx.Send(utils.Error(err)) } // Get the strict from the url params - if err := Utils.GetStrictParam(ctx, &strict); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetStrictParam(ctx, &strict); err != nil { + return ctx.Send(utils.Error(err)) } // Search for the query - if res, err := c.SearchOneWord(Hermes.SearchParams{ + if res, err := c.SearchOneWord(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, }); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else if data, err := json.Marshal(res); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } @@ -98,11 +98,11 @@ func SearchOneWord(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // SearchValues is a handler function that returns a fiber context handler function for searching the cache for values. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that searches the cache for values using the query, limit, and schema parameters provided in the query string and returns a JSON-encoded string of the search results or an error message if the search fails or if the parameters are not provided. -func SearchValues(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func SearchValues(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( query string @@ -112,28 +112,28 @@ func SearchValues(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // Get the query from the url params if query = ctx.Query("query"); len(query) == 0 { - return ctx.Send(Utils.Error("invalid query")) + return ctx.Send(utils.Error("invalid query")) } // Get the limit from the url params - if err := Utils.GetLimitParam(ctx, &limit); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetLimitParam(ctx, &limit); err != nil { + return ctx.Send(utils.Error(err)) } // Get the schema from the url params - if err := Utils.GetSchemaParam(ctx, &schema); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetSchemaParam(ctx, &schema); err != nil { + return ctx.Send(utils.Error(err)) } // Search for the query - if res, err := c.SearchValues(Hermes.SearchParams{ + if res, err := c.SearchValues(hermes.SearchParams{ Query: query, Limit: limit, Schema: schema, }); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else if data, err := json.Marshal(res); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } @@ -142,11 +142,11 @@ func SearchValues(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // SearchWithKey is a handler function that returns a fiber context handler function for searching the cache with a specific key. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that searches the cache with a specific key using the query and limit parameters provided in the query string and returns a JSON-encoded string of the search results or an error message if the search fails or if the parameters are not provided. -func SearchWithKey(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func SearchWithKey(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( key string @@ -156,28 +156,28 @@ func SearchWithKey(c *Hermes.Cache) func(ctx *fiber.Ctx) error { // Get the query from the url params if query = ctx.Query("query"); len(query) == 0 { - return ctx.Send(Utils.Error("invalid query")) + return ctx.Send(utils.Error("invalid query")) } // Get the key from the url params if key = ctx.Query("key"); len(key) == 0 { - return ctx.Send(Utils.Error("invalid key")) + return ctx.Send(utils.Error("invalid key")) } // Get the limit from the url params - if err := Utils.GetLimitParam(ctx, &limit); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetLimitParam(ctx, &limit); err != nil { + return ctx.Send(utils.Error(err)) } // Search for the query - if res, err := c.SearchWithKey(Hermes.SearchParams{ + if res, err := c.SearchWithKey(hermes.SearchParams{ Key: key, Query: query, Limit: limit, }); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else if data, err := json.Marshal(res); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(data) } diff --git a/cloud/api/handlers/set.go b/cloud/api/handlers/set.go index c29a56e..dc135fd 100644 --- a/cloud/api/handlers/set.go +++ b/cloud/api/handlers/set.go @@ -2,17 +2,17 @@ package handlers import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Set is a handler function that returns a fiber context handler function for setting a value in the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that sets a value in the cache using the key and value parameters provided in the query string and returns a success message or an error message if the set fails or if the parameters are not provided. -func Set(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Set(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { var ( key string @@ -20,18 +20,18 @@ func Set(c *Hermes.Cache) func(ctx *fiber.Ctx) error { ) // Get the key from the query if key = ctx.Query("key"); len(key) == 0 { - return ctx.Send(Utils.Error("invalid key")) + return ctx.Send(utils.Error("invalid key")) } // Get the value from the query - if err := Utils.GetValueParam(ctx, &value); err != nil { - return ctx.Send(Utils.Error(err)) + if err := utils.GetValueParam(ctx, &value); err != nil { + return ctx.Send(utils.Error(err)) } // Set the value in the cache if err := c.Set(key, value); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } - return ctx.Send(Utils.Success("null")) + return ctx.Send(utils.Success("null")) } } diff --git a/cloud/api/handlers/values.go b/cloud/api/handlers/values.go index 6db70a3..50f0aad 100644 --- a/cloud/api/handlers/values.go +++ b/cloud/api/handlers/values.go @@ -4,20 +4,20 @@ import ( "encoding/json" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/api/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/api/utils" ) // Values is a handler function that returns a fiber context handler function for getting all values from the cache. // Parameters: -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - func(ctx *fiber.Ctx) error: A fiber context handler function that gets all values from the cache and returns a JSON-encoded string of the values or an error message if the retrieval fails. -func Values(c *Hermes.Cache) func(ctx *fiber.Ctx) error { +func Values(c *hermes.Cache) func(ctx *fiber.Ctx) error { return func(ctx *fiber.Ctx) error { if values, err := json.Marshal(c.Values()); err != nil { - return ctx.Send(Utils.Error(err)) + return ctx.Send(utils.Error(err)) } else { return ctx.Send(values) } diff --git a/cloud/api/routes.go b/cloud/api/routes.go index eb74684..7db5e13 100644 --- a/cloud/api/routes.go +++ b/cloud/api/routes.go @@ -2,21 +2,21 @@ package api import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - "github.com/realTristan/Hermes/cloud/api/handlers" + hermes "github.com/realTristan/hermes" + "github.com/realTristan/hermes/cloud/api/handlers" ) -// SetRoutes is a function that sets the routes for the Hermes Cache API. +// SetRoutes is a function that sets the routes for the hermes Cache API. // Parameters: // - app (*fiber.App): A pointer to a fiber.App struct. -// - cache (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - cache (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - void: This function does not return anything. -func SetRoutes(app *fiber.App, cache *Hermes.Cache) { +func SetRoutes(app *fiber.App, cache *hermes.Cache) { // Dev Testing Handler app.Get("/dev/hermes", func(c *fiber.Ctx) error { - return c.SendString("Hermes Cache API Successfully Running!") + return c.SendString("hermes Cache API Successfully Running!") }) // Cache Handlers @@ -41,7 +41,7 @@ func SetRoutes(app *fiber.App, cache *Hermes.Cache) { app.Get("/ft/search/values", handlers.SearchValues(cache)) app.Get("/ft/search/withkey", handlers.SearchWithKey(cache)) app.Post("/ft/maxbytes", handlers.FTSetMaxBytes(cache)) - app.Post("/ft/maxlength", handlers.FTSetMaxLength(cache)) + app.Post("/ft/maxsize", handlers.FTSetMaxSize(cache)) app.Post("/ft/minwordlength", handlers.FTSetMinWordLength(cache)) app.Get("/ft/storage", handlers.FTStorage(cache)) app.Get("/ft/storage/size", handlers.FTStorageSize(cache)) diff --git a/cloud/api/utils/params.go b/cloud/api/utils/params.go index 7dc47a7..448a339 100644 --- a/cloud/api/utils/params.go +++ b/cloud/api/utils/params.go @@ -24,21 +24,21 @@ func GetValueParam[T any](ctx *fiber.Ctx, value *T) error { return nil } -// GetMaxLengthParam is a function that retrieves the "maxlength" query parameter from a Fiber context and stores it in an integer pointer. +// GetMaxSizeParam is a function that retrieves the "maxsize" query parameter from a Fiber context and stores it in an integer pointer. // Parameters: // - ctx (*fiber.Ctx): A pointer to a Fiber context. -// - maxLength (*int): A pointer to an integer to store the "maxlength" query parameter. +// - maxSize (*int): A pointer to an integer to store the "maxsize" query parameter. // // Returns: -// - error: An error message if the "maxlength" query parameter is invalid or cannot be converted to an integer, or nil if the retrieval is successful. -func GetMaxLengthParam(ctx *fiber.Ctx, maxLength *int) error { - if s := ctx.Query("maxlength"); len(s) == 0 { +// - error: An error message if the "maxsize" query parameter is invalid or cannot be converted to an integer, or nil if the retrieval is successful. +func GetMaxSizeParam(ctx *fiber.Ctx, maxSize *int) error { + if s := ctx.Query("maxsize"); len(s) == 0 { fmt.Println(s) - return errors.New("invalid maxlength") + return errors.New("invalid maxsize") } else if i, err := strconv.Atoi(s); err != nil { return err } else { - *maxLength = i + *maxSize = i } return nil } diff --git a/cloud/app/server/main.go b/cloud/app/server/app.go similarity index 73% rename from cloud/app/server/main.go rename to cloud/app/server/app.go index da5c2da..a8623af 100644 --- a/cloud/app/server/main.go +++ b/cloud/app/server/app.go @@ -4,11 +4,11 @@ import ( "log" "os" - Utils "hermes/utils" + utils "hermes/utils" "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Socket "github.com/realTristan/Hermes/cloud/socket" + hermes "github.com/realTristan/hermes" + Socket "github.com/realTristan/hermes/cloud/socket" ) // Main function @@ -19,18 +19,18 @@ func main() { } // Get the arg data - var args, err = Utils.GetArgData(os.Args) + var args, err = utils.GetArgData(os.Args) if err != nil || args.Port() == nil { panic("incorrect usage. example: ./hermes serve -p {port}") } // Get the port and json file - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize a new fiber app var app *fiber.App = fiber.New(fiber.Config{ Prefork: false, - ServerHeader: "Hermes", + ServerHeader: "hermes", }) Socket.SetRouter(app, cache) diff --git a/cloud/socket/funcs.go b/cloud/socket/funcs.go index f9dcb27..7632338 100644 --- a/cloud/socket/funcs.go +++ b/cloud/socket/funcs.go @@ -1,13 +1,13 @@ package ws import ( - Hermes "github.com/realTristan/Hermes" - "github.com/realTristan/Hermes/cloud/socket/handlers" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + "github.com/realTristan/hermes/cloud/socket/handlers" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Map of functions that can be called from the client -var Functions = map[string]func(*Utils.Params, *Hermes.Cache) []byte{ +var Functions = map[string]func(*utils.Params, *hermes.Cache) []byte{ "cache.length": handlers.Length, "cache.clean": handlers.Clean, "cache.set": handlers.Set, @@ -26,7 +26,7 @@ var Functions = map[string]func(*Utils.Params, *Hermes.Cache) []byte{ "ft.search.values": handlers.SearchValues, "ft.search.withkey": handlers.SearchWithKey, "ft.maxbytes.set": handlers.FTSetMaxBytes, - "ft.maxlength.set": handlers.FTSetMaxLength, + "ft.maxsize.set": handlers.FTSetMaxSize, "ft.storage": handlers.FTStorage, "ft.storage.size": handlers.FTStorageSize, "ft.storage.length": handlers.FTStorageLength, diff --git a/cloud/socket/handlers/clean.go b/cloud/socket/handlers/clean.go index 8d80128..39669ca 100644 --- a/cloud/socket/handlers/clean.go +++ b/cloud/socket/handlers/clean.go @@ -1,32 +1,32 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Clean is a handler function that returns a fiber context handler function for cleaning the cache. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the cleaning fails. -func Clean(_ *Utils.Params, c *Hermes.Cache) []byte { +func Clean(_ *utils.Params, c *hermes.Cache) []byte { c.Clean() - return Utils.Success("null") + return utils.Success("null") } // FTClean is a handler function that returns a fiber context handler function for cleaning the full-text storage. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the cleaning fails. -func FTClean(_ *Utils.Params, c *Hermes.Cache) []byte { +func FTClean(_ *utils.Params, c *hermes.Cache) []byte { if err := c.FTClean(); err != nil { - return Utils.Error(err) + return utils.Error(err) } - return Utils.Success("null") + return utils.Success("null") } diff --git a/cloud/socket/handlers/delete.go b/cloud/socket/handlers/delete.go index 5b07a04..c27f879 100644 --- a/cloud/socket/handlers/delete.go +++ b/cloud/socket/handlers/delete.go @@ -1,28 +1,28 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Delete is a handler function that returns a fiber context handler function for deleting a key from the cache. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the key is not provided or the deletion fails. -func Delete(p *Utils.Params, c *Hermes.Cache) []byte { +func Delete(p *utils.Params, c *hermes.Cache) []byte { // Get the key from the query var ( key string err error ) - if key, err = Utils.GetKeyParam(p); err != nil { - return Utils.Error("key not provided") + if key, err = utils.GetKeyParam(p); err != nil { + return utils.Error("key not provided") } // Delete the key from the cache c.Delete(key) - return Utils.Success("null") + return utils.Success("null") } diff --git a/cloud/socket/handlers/exists.go b/cloud/socket/handlers/exists.go index 1fa0b86..5cd2123 100644 --- a/cloud/socket/handlers/exists.go +++ b/cloud/socket/handlers/exists.go @@ -1,27 +1,27 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Exists is a handler function that returns a fiber context handler function for checking if a key exists in the cache. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a boolean value indicating whether the key exists in the cache or an error message if the key is not provided. -func Exists(p *Utils.Params, c *Hermes.Cache) []byte { +func Exists(p *utils.Params, c *hermes.Cache) []byte { // Get the key from the query var ( key string err error ) - if key, err = Utils.GetKeyParam(p); err != nil { - return Utils.Error("key not provided") + if key, err = utils.GetKeyParam(p); err != nil { + return utils.Error("key not provided") } // Return whether the key exists - return Utils.Success(c.Exists(key)) + return utils.Success(c.Exists(key)) } diff --git a/cloud/socket/handlers/fulltext.go b/cloud/socket/handlers/fulltext.go index d846d19..dadca12 100644 --- a/cloud/socket/handlers/fulltext.go +++ b/cloud/socket/handlers/fulltext.go @@ -3,75 +3,75 @@ package handlers import ( "encoding/json" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // FTIsInitialized is a handler function that returns a fiber context handler function for checking if the full-text storage is initialized. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a boolean value indicating whether the full-text storage is initialized. -func FTIsInitialized(_ *Utils.Params, c *Hermes.Cache) []byte { - return Utils.Success(c.FTIsInitialized()) +func FTIsInitialized(_ *utils.Params, c *hermes.Cache) []byte { + return utils.Success(c.FTIsInitialized()) } // FTSetMaxBytes is a handler function that returns a fiber context handler function for setting the maximum number of bytes for the full-text storage. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the value is invalid or the setting fails. -func FTSetMaxBytes(p *Utils.Params, c *Hermes.Cache) []byte { +func FTSetMaxBytes(p *utils.Params, c *hermes.Cache) []byte { // Get the value from the query var value int - if err := Utils.GetMaxBytesParam(p, &value); err != nil { - return Utils.Error(err) + if err := utils.GetMaxBytesParam(p, &value); err != nil { + return utils.Error(err) } // Set the max bytes if err := c.FTSetMaxBytes(value); err != nil { - return Utils.Error(err) + return utils.Error(err) } - return Utils.Success("null") + return utils.Success("null") } -// FTSetMaxLength is a handler function that returns a fiber context handler function for setting the maximum length for the full-text storage. +// FTSetMaxSize is a handler function that returns a fiber context handler function for setting the maximum length for the full-text storage. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the value is invalid or the setting fails. -func FTSetMaxLength(p *Utils.Params, c *Hermes.Cache) []byte { +func FTSetMaxSize(p *utils.Params, c *hermes.Cache) []byte { // Get the value from the query var value int - if err := Utils.GetMaxLengthParam(p, &value); err != nil { - return Utils.Error(err) + if err := utils.GetMaxSizeParam(p, &value); err != nil { + return utils.Error(err) } // Set the max length - if err := c.FTSetMaxLength(value); err != nil { - return Utils.Error(err) + if err := c.FTSetMaxSize(value); err != nil { + return utils.Error(err) } - return Utils.Success("null") + return utils.Success("null") } // FTStorage is a handler function that returns a fiber context handler function for retrieving the full-text storage. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the full-text storage or an error message if the retrieval fails. -func FTStorage(_ *Utils.Params, c *Hermes.Cache) []byte { +func FTStorage(_ *utils.Params, c *hermes.Cache) []byte { if data, err := c.FTStorage(); err != nil { - return Utils.Error(err) + return utils.Error(err) } else if data, err := json.Marshal(data); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } @@ -79,30 +79,30 @@ func FTStorage(_ *Utils.Params, c *Hermes.Cache) []byte { // FTStorageLength is a handler function that returns a fiber context handler function for retrieving the length of the full-text storage. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the length of the full-text storage or an error message if the retrieval fails. -func FTStorageLength(_ *Utils.Params, c *Hermes.Cache) []byte { +func FTStorageLength(_ *utils.Params, c *hermes.Cache) []byte { if length, err := c.FTStorageLength(); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { - return Utils.Success(length) + return utils.Success(length) } } // FTStorageSize is a handler function that returns a fiber context handler function for retrieving the size of the full-text storage. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the size of the full-text storage or an error message if the retrieval fails. -func FTStorageSize(_ *Utils.Params, c *Hermes.Cache) []byte { +func FTStorageSize(_ *utils.Params, c *hermes.Cache) []byte { if size, err := c.FTStorageSize(); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { - return Utils.Success(size) + return utils.Success(size) } } diff --git a/cloud/socket/handlers/get.go b/cloud/socket/handlers/get.go index 82d98e2..881e8b5 100644 --- a/cloud/socket/handlers/get.go +++ b/cloud/socket/handlers/get.go @@ -3,30 +3,30 @@ package handlers import ( "encoding/json" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Get is a handler function that returns a fiber context handler function for retrieving a key from the cache. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the value of the key or an error message if the key is not provided or the retrieval fails. -func Get(p *Utils.Params, c *Hermes.Cache) []byte { +func Get(p *utils.Params, c *hermes.Cache) []byte { // Get the key from the query var ( key string err error ) - if key, err = Utils.GetKeyParam(p); err != nil { - return Utils.Error("key not provided") + if key, err = utils.GetKeyParam(p); err != nil { + return utils.Error("key not provided") } // Get the value from the cache if data, err := json.Marshal(c.Get(key)); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } @@ -34,11 +34,11 @@ func Get(p *Utils.Params, c *Hermes.Cache) []byte { // GetAll is a handler function that returns a fiber context handler function for retrieving all data from the cache. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing all data from the cache or an error message if the retrieval fails. -func GetAll(_ *Utils.Params, c *Hermes.Cache) []byte { +func GetAll(_ *utils.Params, c *hermes.Cache) []byte { return nil } diff --git a/cloud/socket/handlers/indices.go b/cloud/socket/handlers/indices.go index 13de68a..99df0c9 100644 --- a/cloud/socket/handlers/indices.go +++ b/cloud/socket/handlers/indices.go @@ -1,18 +1,18 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // FTSequenceIndices is a handler function that returns a fiber context handler function for sequencing the full-text storage indices. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the sequencing fails. -func FTSequenceIndices(_ *Utils.Params, c *Hermes.Cache) []byte { +func FTSequenceIndices(_ *utils.Params, c *hermes.Cache) []byte { c.FTSequenceIndices() - return Utils.Success("null") + return utils.Success("null") } diff --git a/cloud/socket/handlers/info.go b/cloud/socket/handlers/info.go index f200076..20ee851 100644 --- a/cloud/socket/handlers/info.go +++ b/cloud/socket/handlers/info.go @@ -1,38 +1,38 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Info is a function that returns information about the cache. // // Parameters: -// - _ : A pointer to a Utils.Params struct representing the parameters of the request. This parameter is ignored. -// - c: A pointer to a Hermes.Cache struct representing the cache to get information from. +// - _ : A pointer to a utils.Params struct representing the parameters of the request. This parameter is ignored. +// - c: A pointer to a hermes.Cache struct representing the cache to get information from. // // Returns: // - A byte slice representing the information about the cache. -func Info(_ *Utils.Params, c *Hermes.Cache) []byte { +func Info(_ *utils.Params, c *hermes.Cache) []byte { if info, err := c.Info(); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { - return Utils.Success(info) + return utils.Success(info) } } // InfoForTesting is a function that returns information about the cache for testing purposes. // // Parameters: -// - _ : A pointer to a Utils.Params struct representing the parameters of the request. This parameter is ignored. -// - c: A pointer to a Hermes.Cache struct representing the cache to get information from. +// - _ : A pointer to a utils.Params struct representing the parameters of the request. This parameter is ignored. +// - c: A pointer to a hermes.Cache struct representing the cache to get information from. // // Returns: // - A byte slice representing the information about the cache for testing purposes. -func InfoForTesting(_ *Utils.Params, c *Hermes.Cache) []byte { +func InfoForTesting(_ *utils.Params, c *hermes.Cache) []byte { if info, err := c.InfoForTesting(); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { - return Utils.Success(info) + return utils.Success(info) } } diff --git a/cloud/socket/handlers/init.go b/cloud/socket/handlers/init.go index 6221706..e4b5d33 100644 --- a/cloud/socket/handlers/init.go +++ b/cloud/socket/handlers/init.go @@ -1,86 +1,86 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // FTInit is a handler function that returns a fiber context handler function for initializing the full-text search cache. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the initialization fails. -func FTInit(p *Utils.Params, c *Hermes.Cache) []byte { +func FTInit(p *utils.Params, c *hermes.Cache) []byte { var ( - maxLength int + maxSize int maxBytes int minWordLength int ) // Get the max length parameter - if err := Utils.GetMaxLengthParam(p, &maxLength); err != nil { - return Utils.Error(err) + if err := utils.GetMaxSizeParam(p, &maxSize); err != nil { + return utils.Error(err) } // Get the max bytes parameter - if err := Utils.GetMaxBytesParam(p, &maxBytes); err != nil { - return Utils.Error(err) + if err := utils.GetMaxBytesParam(p, &maxBytes); err != nil { + return utils.Error(err) } // Get the min word length parameter - if err := Utils.GetMinWordLengthParam(p, &minWordLength); err != nil { - return Utils.Error(err) + if err := utils.GetMinWordLengthParam(p, &minWordLength); err != nil { + return utils.Error(err) } // Initialize the full-text cache - if err := c.FTInit(maxLength, maxBytes, minWordLength); err != nil { - return Utils.Error(err) + if err := c.FTInit(maxSize, maxBytes, minWordLength); err != nil { + return utils.Error(err) } - return Utils.Success("null") + return utils.Success("null") } // FTInitJson is a handler function that returns a fiber context handler function for initializing the full-text search cache with a JSON object. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the initialization fails. -func FTInitJson(p *Utils.Params, c *Hermes.Cache) []byte { +func FTInitJson(p *utils.Params, c *hermes.Cache) []byte { var ( - maxLength int + maxSize int maxBytes int minWordLength int json map[string]map[string]any ) // Get the max length from the query - if err := Utils.GetMaxLengthParam(p, &maxLength); err != nil { - return Utils.Error(err) + if err := utils.GetMaxSizeParam(p, &maxSize); err != nil { + return utils.Error(err) } // Get the max bytes from the query - if err := Utils.GetMaxBytesParam(p, &maxBytes); err != nil { - return Utils.Error(err) + if err := utils.GetMaxBytesParam(p, &maxBytes); err != nil { + return utils.Error(err) } // Get the min word length from the query - if err := Utils.GetMinWordLengthParam(p, &minWordLength); err != nil { - return Utils.Error(err) + if err := utils.GetMinWordLengthParam(p, &minWordLength); err != nil { + return utils.Error(err) } // Get the JSON from the query - if err := Utils.GetJSONParam(p, &json); err != nil { - return Utils.Error(err) + if err := utils.GetJSONParam(p, &json); err != nil { + return utils.Error(err) } // Initialize the full-text cache - if err := c.FTInitWithMap(json, maxLength, maxBytes, minWordLength); err != nil { - return Utils.Error(err) + if err := c.FTInitWithMap(json, maxSize, maxBytes, minWordLength); err != nil { + return utils.Error(err) } // Return success message - return Utils.Success("null") + return utils.Success("null") } diff --git a/cloud/socket/handlers/keys.go b/cloud/socket/handlers/keys.go index e181a6c..bd84bcd 100644 --- a/cloud/socket/handlers/keys.go +++ b/cloud/socket/handlers/keys.go @@ -3,20 +3,20 @@ package handlers import ( "encoding/json" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Keys is a handler function that returns a fiber context handler function for retrieving all keys from the cache. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing all keys from the cache or an error message if the retrieval fails. -func Keys(_ *Utils.Params, c *Hermes.Cache) []byte { +func Keys(_ *utils.Params, c *hermes.Cache) []byte { if keys, err := json.Marshal(c.Keys()); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return keys } diff --git a/cloud/socket/handlers/length.go b/cloud/socket/handlers/length.go index 40eb160..da02ae9 100644 --- a/cloud/socket/handlers/length.go +++ b/cloud/socket/handlers/length.go @@ -1,17 +1,17 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Length is a handler function that returns a fiber context handler function for retrieving the length of the cache. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the length of the cache. -func Length(_ *Utils.Params, c *Hermes.Cache) []byte { - return Utils.Success(c.Length()) +func Length(_ *utils.Params, c *hermes.Cache) []byte { + return utils.Success(c.Length()) } diff --git a/cloud/socket/handlers/search.go b/cloud/socket/handlers/search.go index a56e507..49450ce 100644 --- a/cloud/socket/handlers/search.go +++ b/cloud/socket/handlers/search.go @@ -3,18 +3,18 @@ package handlers import ( "encoding/json" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Search is a handler function that returns a fiber context handler function for searching the cache for a query. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the search results or an error message if the search fails. -func Search(p *Utils.Params, c *Hermes.Cache) []byte { +func Search(p *utils.Params, c *hermes.Cache) []byte { var ( strict bool query string @@ -23,29 +23,29 @@ func Search(p *Utils.Params, c *Hermes.Cache) []byte { ) // Get the query from the params - if query, err = Utils.GetQueryParam(p); err != nil { - return Utils.Error("query not provided") + if query, err = utils.GetQueryParam(p); err != nil { + return utils.Error("query not provided") } // Get the limit from the params - if err := Utils.GetLimitParam(p, &limit); err != nil { - return Utils.Error(err) + if err := utils.GetLimitParam(p, &limit); err != nil { + return utils.Error(err) } // Get the strict from the params - if err := Utils.GetStrictParam(p, &strict); err != nil { - return Utils.Error(err) + if err := utils.GetStrictParam(p, &strict); err != nil { + return utils.Error(err) } // Search for the query - if res, err := c.Search(Hermes.SearchParams{ + if res, err := c.Search(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, }); err != nil { - return Utils.Error(err) + return utils.Error(err) } else if data, err := json.Marshal(res); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } @@ -53,12 +53,12 @@ func Search(p *Utils.Params, c *Hermes.Cache) []byte { // SearchOneWord is a handler function that returns a fiber context handler function for searching the cache for a single word query. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the search results or an error message if the search fails. -func SearchOneWord(p *Utils.Params, c *Hermes.Cache) []byte { +func SearchOneWord(p *utils.Params, c *hermes.Cache) []byte { var ( strict bool query string @@ -67,30 +67,30 @@ func SearchOneWord(p *Utils.Params, c *Hermes.Cache) []byte { ) // Get the query from the params - if query, err = Utils.GetQueryParam(p); err != nil { - return Utils.Error("invalid query") + if query, err = utils.GetQueryParam(p); err != nil { + return utils.Error("invalid query") } // Get the limit from the params - if err := Utils.GetLimitParam(p, &limit); err != nil { - return Utils.Error(err) + if err := utils.GetLimitParam(p, &limit); err != nil { + return utils.Error(err) } // Get the strict from the params - if err := Utils.GetStrictParam(p, &strict); err != nil { - return Utils.Error(err) + if err := utils.GetStrictParam(p, &strict); err != nil { + return utils.Error(err) } // Search for the query - if res, err := c.SearchOneWord(Hermes.SearchParams{ + if res, err := c.SearchOneWord(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, }); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { if data, err := json.Marshal(res); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } @@ -99,12 +99,12 @@ func SearchOneWord(p *Utils.Params, c *Hermes.Cache) []byte { // SearchValues is a handler function that returns a fiber context handler function for searching the cache for a query in values. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the search results or an error message if the search fails. -func SearchValues(p *Utils.Params, c *Hermes.Cache) []byte { +func SearchValues(p *utils.Params, c *hermes.Cache) []byte { var ( query string limit int @@ -113,30 +113,30 @@ func SearchValues(p *Utils.Params, c *Hermes.Cache) []byte { ) // Get the query from the params - if query, err = Utils.GetQueryParam(p); err != nil { - return Utils.Error("invalid query") + if query, err = utils.GetQueryParam(p); err != nil { + return utils.Error("invalid query") } // Get the limit from the params - if err := Utils.GetLimitParam(p, &limit); err != nil { - return Utils.Error(err) + if err := utils.GetLimitParam(p, &limit); err != nil { + return utils.Error(err) } // Get the schema from the params - if err := Utils.GetSchemaParam(p, &schema); err != nil { - return Utils.Error(err) + if err := utils.GetSchemaParam(p, &schema); err != nil { + return utils.Error(err) } // Search for the query - if res, err := c.SearchValues(Hermes.SearchParams{ + if res, err := c.SearchValues(hermes.SearchParams{ Query: query, Limit: limit, Schema: schema, }); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { if data, err := json.Marshal(res); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } @@ -145,12 +145,12 @@ func SearchValues(p *Utils.Params, c *Hermes.Cache) []byte { // SearchWithKey is a handler function that returns a fiber context handler function for searching the cache for a query with a specific key. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing the search results or an error message if the search fails. -func SearchWithKey(p *Utils.Params, c *Hermes.Cache) []byte { +func SearchWithKey(p *utils.Params, c *hermes.Cache) []byte { var ( key string query string @@ -160,35 +160,35 @@ func SearchWithKey(p *Utils.Params, c *Hermes.Cache) []byte { ) // Get the query from the params - if query, err = Utils.GetQueryParam(p); err != nil { - return Utils.Error("invalid query") + if query, err = utils.GetQueryParam(p); err != nil { + return utils.Error("invalid query") } // Get the key from the params - if key, err = Utils.GetKeyParam(p); err != nil { - return Utils.Error("invalid key") + if key, err = utils.GetKeyParam(p); err != nil { + return utils.Error("invalid key") } // Get the limit from the params - if err := Utils.GetLimitParam(p, &limit); err != nil { - return Utils.Error(err) + if err := utils.GetLimitParam(p, &limit); err != nil { + return utils.Error(err) } // Get the schema from the params - if err := Utils.GetSchemaParam(p, &schema); err != nil { - return Utils.Error(err) + if err := utils.GetSchemaParam(p, &schema); err != nil { + return utils.Error(err) } // Search for the query - if res, err := c.SearchWithKey(Hermes.SearchParams{ + if res, err := c.SearchWithKey(hermes.SearchParams{ Query: query, Key: key, Limit: limit, }); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { if data, err := json.Marshal(res); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return data } diff --git a/cloud/socket/handlers/set.go b/cloud/socket/handlers/set.go index aa77b3b..e1547b3 100644 --- a/cloud/socket/handlers/set.go +++ b/cloud/socket/handlers/set.go @@ -1,18 +1,18 @@ package handlers import ( - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Set is a handler function that returns a fiber context handler function for setting a value in the cache. // Parameters: -// - p (*Utils.Params): A pointer to a Utils.Params struct. -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - p (*utils.Params): A pointer to a utils.Params struct. +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing a success message or an error message if the set operation fails. -func Set(p *Utils.Params, c *Hermes.Cache) []byte { +func Set(p *utils.Params, c *hermes.Cache) []byte { var ( key string err error @@ -20,18 +20,18 @@ func Set(p *Utils.Params, c *Hermes.Cache) []byte { ) // Get the key from the query - if key, err = Utils.GetKeyParam(p); err != nil { - return Utils.Error("invalid key") + if key, err = utils.GetKeyParam(p); err != nil { + return utils.Error("invalid key") } // Get the value from the query - if err := Utils.GetValueParam(p, &value); err != nil { - return Utils.Error(err) + if err := utils.GetValueParam(p, &value); err != nil { + return utils.Error(err) } // Set the value in the cache if err := c.Set(key, value); err != nil { - return Utils.Error(err) + return utils.Error(err) } - return Utils.Success("null") + return utils.Success("null") } diff --git a/cloud/socket/handlers/values.go b/cloud/socket/handlers/values.go index 67a6634..2becf78 100644 --- a/cloud/socket/handlers/values.go +++ b/cloud/socket/handlers/values.go @@ -3,20 +3,20 @@ package handlers import ( "encoding/json" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Values is a handler function that returns a fiber context handler function for retrieving all values from the cache. // Parameters: -// - _ (*Utils.Params): A pointer to a Utils.Params struct (unused). -// - c (*Hermes.Cache): A pointer to a Hermes.Cache struct. +// - _ (*utils.Params): A pointer to a utils.Params struct (unused). +// - c (*hermes.Cache): A pointer to a hermes.Cache struct. // // Returns: // - []byte: A JSON-encoded byte slice containing all values from the cache or an error message if the retrieval fails. -func Values(_ *Utils.Params, c *Hermes.Cache) []byte { +func Values(_ *utils.Params, c *hermes.Cache) []byte { if values, err := json.Marshal(c.Values()); err != nil { - return Utils.Error(err) + return utils.Error(err) } else { return values } diff --git a/cloud/socket/router.go b/cloud/socket/router.go index cc813e9..b147edb 100644 --- a/cloud/socket/router.go +++ b/cloud/socket/router.go @@ -6,12 +6,12 @@ import ( "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" - Hermes "github.com/realTristan/Hermes" - Utils "github.com/realTristan/Hermes/cloud/socket/utils" + hermes "github.com/realTristan/hermes" + utils "github.com/realTristan/hermes/cloud/socket/utils" ) // Set the router for the socket -func SetRouter(app *fiber.App, cache *Hermes.Cache) { +func SetRouter(app *fiber.App, cache *hermes.Cache) { // Init a new socket var socket *Socket = &Socket{ active: false, @@ -59,8 +59,8 @@ func SetRouter(app *fiber.App, cache *Hermes.Cache) { } // Get the data - var p *Utils.Params - if p, err = Utils.ParseParams(msg); err != nil { + var p *utils.Params + if p, err = utils.ParseParams(msg); err != nil { log.Println("parse:", err) break } diff --git a/cloud/socket/utils/params.go b/cloud/socket/utils/params.go index ac76ba3..32a6efb 100644 --- a/cloud/socket/utils/params.go +++ b/cloud/socket/utils/params.go @@ -93,18 +93,18 @@ func GetValueParam[T any](p *Params, value *T) error { return nil } -// GetMaxLengthParam is a function that retrieves the value of the "maxlength" query parameter from a Params struct and stores it in a provided integer pointer. +// GetMaxSizeParam is a function that retrieves the value of the "maxsize" query parameter from a Params struct and stores it in a provided integer pointer. // Parameters: // - p (*Params): A pointer to a Params struct. -// - maxLength (*int): A pointer to an integer to store the value of the "maxlength" query parameter. +// - maxSize (*int): A pointer to an integer to store the value of the "maxsize" query parameter. // // Returns: -// - error: An error if the "maxlength" query parameter is not provided or is not a float64, or nil if successful. -func GetMaxLengthParam(p *Params, maxLength *int) error { - if i, ok := p.Get("maxlength").(float64); !ok { - return errors.New("invalid maxlength") +// - error: An error if the "maxsize" query parameter is not provided or is not a float64, or nil if successful. +func GetMaxSizeParam(p *Params, maxSize *int) error { + if i, ok := p.Get("maxsize").(float64); !ok { + return errors.New("invalid maxsize") } else { - *maxLength = int(i) + *maxSize = int(i) } return nil } diff --git a/examples/basic/basic.go b/examples/basic/basic.go index ad2372b..90b333c 100644 --- a/examples/basic/basic.go +++ b/examples/basic/basic.go @@ -14,11 +14,11 @@ import ( "strconv" "time" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) // Initialize the cache -var cache *Hermes.Cache = Hermes.InitCache() +var cache *hermes.Cache = hermes.InitCache() // Main function func main() { @@ -61,7 +61,7 @@ func Handler(w http.ResponseWriter, r *http.Request) { // Search for a word in the cache // Make sure the show which keys you do want to search through, // and which ones you don't - var res, _ = cache.Search(Hermes.SearchParams{ + var res, _ = cache.Search(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, diff --git a/examples/router/main.go b/examples/router/router.go similarity index 92% rename from examples/router/main.go rename to examples/router/router.go index 789f9f7..6567b32 100644 --- a/examples/router/main.go +++ b/examples/router/router.go @@ -14,15 +14,15 @@ import ( "strconv" "time" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) // Global full text variable -var cache *Hermes.Cache +var cache *hermes.Cache // Main function func main() { - cache = Hermes.InitCache() + cache = hermes.InitCache() cache.FTInitWithJson("../../testing/data/data_hash.json", -1, -1, 3) // Print host @@ -61,7 +61,7 @@ func Handler(w http.ResponseWriter, r *http.Request) { // Search for a word in the cache // Make sure the show which keys you do want to search through, // and which ones you don't - var res, _ = cache.Search(Hermes.SearchParams{ + var res, _ = cache.Search(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, diff --git a/fulltext.go b/fulltext.go index 8e21ac9..062dc89 100644 --- a/fulltext.go +++ b/fulltext.go @@ -3,7 +3,7 @@ package hermes import ( "errors" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // FullText is a struct that represents a full-text index for a cache of data. @@ -13,14 +13,14 @@ import ( // - storage (map[string]any): A map that stores the indices of the entries in the cache that contain each word in the full-text index. The keys of the map are strings that represent the words in the index, and the values are slices of integers that represent the indices of the entries in the cache that contain the word. // - indices (map[int]string): A map that stores the words in the full-text index. The keys of the map are integers that represent the indices of the words in the index, and the values are strings that represent the words. // - index (int): An integer that represents the current index of the full-text index. This is used to assign unique indices to new words as they are added to the index. -// - maxLength (int): An integer that represents the maximum number of words that can be stored in the full-text index. +// - maxSize (int): An integer that represents the maximum number of words that can be stored in the full-text index. // - maxBytes (int): An integer that represents the maximum size of the text that can be stored in the full-text index, in bytes. // - minWordLength (int): An integer that represents the minimum length of a word that can be stored in the full-text index. type FullText struct { storage map[string]any // either []int or int indices map[int]string index int - maxLength int + maxSize int maxBytes int minWordLength int } @@ -66,7 +66,7 @@ func (c *Cache) FTSetMaxBytes(maxBytes int) error { } // Check if the current size of the storage is greater than the new max size - if i, err := Utils.Size(c.ft.storage); err != nil { + if i, err := utils.Size(c.ft.storage); err != nil { return err } else if i > maxBytes { return errors.New("the current size of the full-text storage is greater than the new max size") @@ -79,18 +79,18 @@ func (c *Cache) FTSetMaxBytes(maxBytes int) error { return nil } -// FTSetMaxLength is a method of the Cache struct that sets the maximum number of words in the full-text index. +// FTSetMaxSize is a method of the Cache struct that sets the maximum number of words in the full-text index. // If the full-text index is not initialized, this method returns an error. // If the current size of the full-text index is greater than the new maximum size, this method returns an error. // Otherwise, the maximum number of words in the full-text index is set to the specified value, and this method returns nil. // This method is thread-safe. // // Parameters: -// - maxLength (int): An integer that represents the new maximum number of words in the full-text index. +// - maxSize (int): An integer that represents the new maximum number of words in the full-text index. // // Returns: // - error: An error object. If no error occurs, this will be nil. -func (c *Cache) FTSetMaxLength(maxLength int) error { +func (c *Cache) FTSetMaxSize(maxSize int) error { c.mutex.Lock() defer c.mutex.Unlock() @@ -100,17 +100,17 @@ func (c *Cache) FTSetMaxLength(maxLength int) error { } // Check if the current size of the storage is the same as the new max size - if maxLength == c.ft.maxLength { + if maxSize == c.ft.maxSize { return nil } // Check if the current size of the storage is greater than the new max size - if len(c.ft.storage) > maxLength { + if len(c.ft.storage) > maxSize { return errors.New("the current size of the full-text storage is greater than the new max size") } - // Set the maxLength field - c.ft.maxLength = maxLength + // Set the maxSize field + c.ft.maxSize = maxSize // Return no error return nil @@ -139,7 +139,7 @@ func (c *Cache) FTSetMinWordLength(minWordLength int) error { // If the new min word length is greater than the max // word length, reset the ft if minWordLength > c.ft.minWordLength { - return c.ftInit(c.ft.maxBytes, c.ft.maxLength, minWordLength) + return c.ftInit(c.ft.maxBytes, c.ft.maxSize, minWordLength) } // Set the minWordLength field @@ -200,7 +200,7 @@ func (c *Cache) FTStorageSize() (int, error) { } // Return the size of the storage map - return Utils.Size(c.ft.storage) + return utils.Size(c.ft.storage) } // FTStorageLength is a method of the Cache struct that returns the number of words in the full-text index storage. diff --git a/go.mod b/go.mod index 2acbf91..8353713 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/realTristan/Hermes +module github.com/realTristan/hermes go 1.20 diff --git a/info.go b/info.go index d7bd8ad..037f514 100644 --- a/info.go +++ b/info.go @@ -3,7 +3,7 @@ package hermes import ( "errors" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // Info is a method of the Cache struct that returns a map with the cache and full-text info. @@ -37,7 +37,7 @@ func (c *Cache) info() (map[string]any, error) { } // Add the full-text info to the map - if size, err := Utils.Size(c.ft.storage); err != nil { + if size, err := utils.Size(c.ft.storage); err != nil { return info, err } else { // Add the full-text info to the map @@ -84,7 +84,7 @@ func (c *Cache) infoForTesting() (map[string]any, error) { } // Add the full-text info to the map - if size, err := Utils.Size(c.ft.storage); err != nil { + if size, err := utils.Size(c.ft.storage); err != nil { return info, err } else { info["full-text"] = map[string]any{ diff --git a/init.go b/init.go index 3ae2e94..153bbb9 100644 --- a/init.go +++ b/init.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // InitCache is a function that initializes a new Cache struct and returns a pointer to it. @@ -64,12 +64,12 @@ func (ft *FullText) initInsert(data *map[string]map[string]any) error { // If the full-text index is already initialized, an error is returned. // // Parameters: -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error: If the full-text is already initialized. -func (c *Cache) FTInit(maxLength int, maxBytes int, minWordLength int) error { +func (c *Cache) FTInit(maxSize int, maxBytes int, minWordLength int) error { c.mutex.Lock() defer c.mutex.Unlock() @@ -79,25 +79,25 @@ func (c *Cache) FTInit(maxLength int, maxBytes int, minWordLength int) error { } // Initialize the FT - return c.ftInit(maxLength, maxBytes, minWordLength) + return c.ftInit(maxSize, maxBytes, minWordLength) } // Initialize the full-text for the cache. // This method is not thread-safe, and should only be called from an exported function. // // Parameters: -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error: From full-text cache insertion. -func (c *Cache) ftInit(maxLength int, maxBytes int, minWordLength int) error { +func (c *Cache) ftInit(maxSize int, maxBytes int, minWordLength int) error { // Initialize the FT struct var ft *FullText = &FullText{ storage: make(map[string]any), indices: make(map[int]string), index: 0, - maxLength: maxLength, + maxSize: maxSize, maxBytes: maxBytes, minWordLength: minWordLength, } @@ -120,12 +120,12 @@ func (c *Cache) ftInit(maxLength int, maxBytes int, minWordLength int) error { // // Parameters: // - data: the data to initialize the full-text index with. -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error: If the full-text is already initialized. -func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxLength int, maxBytes int, minWordLength int) error { +func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxSize int, maxBytes int, minWordLength int) error { c.mutex.Lock() defer c.mutex.Unlock() @@ -135,7 +135,7 @@ func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxLength int, max } // Initialize the FT cache - return c.ftInitWithMap(data, maxLength, maxBytes, minWordLength) + return c.ftInitWithMap(data, maxSize, maxBytes, minWordLength) } // Initialize the full-text for the cache with a map. @@ -143,18 +143,18 @@ func (c *Cache) FTInitWithMap(data map[string]map[string]any, maxLength int, max // // Parameters: // - data: the data to initialize the full-text index with. -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error -func (c *Cache) ftInitWithMap(data map[string]map[string]any, maxLength int, maxBytes int, minWordLength int) error { +func (c *Cache) ftInitWithMap(data map[string]map[string]any, maxSize int, maxBytes int, minWordLength int) error { // Initialize the FT struct var ft *FullText = &FullText{ storage: make(map[string]any), indices: make(map[int]string), index: 0, - maxLength: maxLength, + maxSize: maxSize, maxBytes: maxBytes, minWordLength: minWordLength, } @@ -186,12 +186,12 @@ func (c *Cache) ftInitWithMap(data map[string]map[string]any, maxLength int, max // // Parameters: // - file: the path to the JSON file to initialize the full-text index with. -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error: If the full-text is already initialized. -func (c *Cache) FTInitWithJson(file string, maxLength int, maxBytes int, minWordLength int) error { +func (c *Cache) FTInitWithJson(file string, maxSize int, maxBytes int, minWordLength int) error { c.mutex.Lock() defer c.mutex.Unlock() @@ -201,7 +201,7 @@ func (c *Cache) FTInitWithJson(file string, maxLength int, maxBytes int, minWord } // Initialize the FT - return c.ftInitWithJson(file, maxLength, maxBytes, minWordLength) + return c.ftInitWithJson(file, maxSize, maxBytes, minWordLength) } // Initialize the full-text for the cache with a JSON file. @@ -209,15 +209,15 @@ func (c *Cache) FTInitWithJson(file string, maxLength int, maxBytes int, minWord // // Parameters: // - file: the path to the JSON file to initialize the full-text index with. -// - maxLength: the maximum number of words to store in the full-text index. +// - maxSize: the maximum number of words to store in the full-text index. // - maxBytes: the maximum size, in bytes, of the full-text index. // // Returns: // - error: Json file read error, or init with map error. -func (c *Cache) ftInitWithJson(file string, maxLength int, maxBytes int, minWordLength int) error { - if data, err := Utils.ReadJson[map[string]map[string]any](file); err != nil { +func (c *Cache) ftInitWithJson(file string, maxSize int, maxBytes int, minWordLength int) error { + if data, err := utils.ReadJson[map[string]map[string]any](file); err != nil { return err } else { - return c.ftInitWithMap(data, maxLength, maxBytes, minWordLength) + return c.ftInitWithMap(data, maxSize, maxBytes, minWordLength) } } diff --git a/nocache/examples/main/main.go b/nocache/examples/basic/basic.go similarity index 82% rename from nocache/examples/main/main.go rename to nocache/examples/basic/basic.go index 44e89cc..29e1bc2 100644 --- a/nocache/examples/main/main.go +++ b/nocache/examples/basic/basic.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - Hermes "github.com/realTristan/Hermes/nocache" + hermes "github.com/realTristan/hermes/nocache" ) // Main function @@ -12,14 +12,14 @@ func main() { // Define variables var ( // Initialize the full text - ft, _ = Hermes.InitWithJson("../../../testing/data/data_array.json", 3) + ft, _ = hermes.InitWithJson("../../../testing/data/data_array.json", 3) // Track the start time start time.Time = time.Now() // Search for a word in the cache // @params: query, limit, strict - res, _ = ft.Search(Hermes.SearchParams{ + res, _ = ft.Search(hermes.SearchParams{ Query: "computer", Limit: 100, Strict: false, diff --git a/nocache/examples/router/router.go b/nocache/examples/router/router.go index 215db07..fd0d244 100644 --- a/nocache/examples/router/router.go +++ b/nocache/examples/router/router.go @@ -14,15 +14,15 @@ import ( "strconv" "time" - Hermes "github.com/realTristan/Hermes/nocache" + hermes "github.com/realTristan/hermes/nocache" ) // Global full text variable -var ft *Hermes.FullText +var ft *hermes.FullText // Main function func main() { - ft, _ = Hermes.InitWithJson("../../../testing/data/data_array.json", 3) + ft, _ = hermes.InitWithJson("../../../testing/data/data_array.json", 3) // Print host fmt.Println(" >> Listening on: http://localhost:8000/") @@ -60,7 +60,7 @@ func Handler(w http.ResponseWriter, r *http.Request) { // Search for a word in the cache // Make sure the show which keys you do want to search through, // and which ones you don't - var res, _ = ft.Search(Hermes.SearchParams{ + var res, _ = ft.Search(hermes.SearchParams{ Query: query, Limit: limit, Strict: strict, diff --git a/nocache/init.go b/nocache/init.go index 03056da..8508966 100644 --- a/nocache/init.go +++ b/nocache/init.go @@ -3,7 +3,7 @@ package nocache import ( "sync" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // Initialize the full-text cache with the provided data. @@ -32,7 +32,7 @@ func InitWithMapSlice(data []map[string]any, minWordLength int) (*FullText, erro // This function is thread safe. func InitWithJson(file string, minWordLength int) (*FullText, error) { // Read the json data - if data, err := Utils.ReadJson[[]map[string]any](file); err != nil { + if data, err := utils.ReadJson[[]map[string]any](file); err != nil { return nil, err } else { return InitWithMapSlice(data, minWordLength) diff --git a/nocache/insert.go b/nocache/insert.go index 65e999e..4bcf995 100644 --- a/nocache/insert.go +++ b/nocache/insert.go @@ -3,7 +3,7 @@ package nocache import ( "strings" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // Insert data into the full-text cache. @@ -28,7 +28,7 @@ func (ft *FullText) insert(data []map[string]any, minWordLength int) error { // Clean the value strv = strings.TrimSpace(strv) - strv = Utils.RemoveDoubleSpaces(strv) + strv = utils.RemoveDoubleSpaces(strv) strv = strings.ToLower(strv) // Loop through the words @@ -38,8 +38,8 @@ func (ft *FullText) insert(data []map[string]any, minWordLength int) error { } // Trim the word - word = Utils.TrimNonAlphaNum(word) - var words []string = Utils.SplitByAlphaNum(word) + word = utils.TrimNonAlphaNum(word) + var words []string = utils.SplitByAlphaNum(word) // Loop through the words for j := 0; j < len(words); j++ { @@ -52,7 +52,7 @@ func (ft *FullText) insert(data []map[string]any, minWordLength int) error { } else if indices, ok := temp.([]int); !ok { ft.storage[words[j]] = []int{temp.(int), i} } else { - if Utils.SliceContains(indices, i) { + if utils.SliceContains(indices, i) { continue } ft.storage[words[j]] = append(indices, i) diff --git a/nocache/searchoneword.go b/nocache/searchoneword.go index 32d0083..fcda22c 100644 --- a/nocache/searchoneword.go +++ b/nocache/searchoneword.go @@ -4,7 +4,7 @@ import ( "errors" "strings" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // SearchOneWord searches for a single query within the data using a full-text search approach. @@ -69,7 +69,7 @@ func (ft *FullText) searchOneWord(sp SearchParams) []map[string]any { switch { case len(result) >= sp.Limit: return result - case !Utils.Contains(ft.words[i], sp.Query): + case !utils.Contains(ft.words[i], sp.Query): continue } diff --git a/searchoneword.go b/searchoneword.go index b52ec82..dc13ac6 100644 --- a/searchoneword.go +++ b/searchoneword.go @@ -4,7 +4,7 @@ import ( "errors" "strings" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // SearchOneWord searches for a single word in the FullText struct's data and returns a list of maps containing the search results. @@ -69,7 +69,7 @@ func (c *Cache) searchOneWord(sp SearchParams) []map[string]any { switch { case len(result) >= sp.Limit: return result - case !Utils.Contains(k, sp.Query): + case !utils.Contains(k, sp.Query): continue } diff --git a/temp_storage.go b/temp_storage.go index c9d2768..d3464b7 100644 --- a/temp_storage.go +++ b/temp_storage.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - Utils "github.com/realTristan/Hermes/utils" + utils "github.com/realTristan/hermes/utils" ) // NewTempStorage is a function that creates a new TempStorage object for a given FullText object. @@ -75,13 +75,13 @@ func (ts *TempStorage) cleanSingleArrays() { // - (error): An error if the storage limit has been reached, nil otherwise. func (ts *TempStorage) error(ft *FullText) error { // Check if the storage limit has been reached - if ft.maxLength > 0 { - if len(ts.data) > ft.maxLength { - return fmt.Errorf("full-text storage limit reached (%d/%d keys). load cancelled", len(ts.data), ft.maxLength) + if ft.maxSize > 0 { + if len(ts.data) > ft.maxSize { + return fmt.Errorf("full-text storage limit reached (%d/%d keys). load cancelled", len(ts.data), ft.maxSize) } } if ft.maxBytes > 0 { - if cacheSize, err := Utils.Size(ts.data); err != nil { + if cacheSize, err := utils.Size(ts.data); err != nil { return err } else if cacheSize > ft.maxBytes { return fmt.Errorf("full-text byte-size limit reached (%d/%d bytes). load cancelled", cacheSize, ft.maxBytes) @@ -112,7 +112,7 @@ func (ts *TempStorage) update(ft *FullText, words []string, cacheKey string) { } else if v, ok := temp.([]int); !ok { ts.data[word] = []int{temp.(int), ts.keys[cacheKey]} } else { - if Utils.SliceContains(v, ts.keys[cacheKey]) { + if utils.SliceContains(v, ts.keys[cacheKey]) { continue } ts.data[word] = append(v, ts.keys[cacheKey]) @@ -148,7 +148,7 @@ func (ts *TempStorage) insert(ft *FullText, cacheKey string, ftv string) error { // Clean the string value ftv = strings.TrimSpace(ftv) - ftv = Utils.RemoveDoubleSpaces(ftv) + ftv = utils.RemoveDoubleSpaces(ftv) ftv = strings.ToLower(ftv) // Loop through the words @@ -162,8 +162,8 @@ func (ts *TempStorage) insert(ft *FullText, cacheKey string, ftv string) error { } // Trim the word - word = Utils.TrimNonAlphaNum(word) - var words []string = Utils.SplitByAlphaNum(word) + word = utils.TrimNonAlphaNum(word) + var words []string = utils.SplitByAlphaNum(word) // Update the temp storage ts.update(ft, words, cacheKey) diff --git a/testing/api/test_withjson.py b/testing/api/request.py similarity index 100% rename from testing/api/test_withjson.py rename to testing/api/request.py diff --git a/testing/api/router.go b/testing/api/router.go index 1c40249..c2f1957 100644 --- a/testing/api/router.go +++ b/testing/api/router.go @@ -2,13 +2,13 @@ package main import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - api "github.com/realTristan/Hermes/api" + hermes "github.com/realTristan/hermes" + api "github.com/realTristan/hermes/cloud/api" ) func main() { app := fiber.New() - cache := Hermes.InitCache() + cache := hermes.InitCache() api.SetRoutes(app, cache) app.Listen(":3000") } diff --git a/testing/cache/cache.go b/testing/cache/cache.go index 3b680fb..aa618ce 100644 --- a/testing/cache/cache.go +++ b/testing/cache/cache.go @@ -3,7 +3,7 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + Hermes "github.com/realTristan/hermes" ) func main() { diff --git a/compression/testing/main.go b/testing/compression/compression.go similarity index 87% rename from compression/testing/main.go rename to testing/compression/compression.go index 9ed0f62..6284b24 100644 --- a/compression/testing/main.go +++ b/testing/compression/compression.go @@ -5,9 +5,9 @@ import ( "strings" "time" - gzip "github.com/realTristan/Hermes/compression/gzip" - "github.com/realTristan/Hermes/compression/zlib" - utils "github.com/realTristan/Hermes/utils" + gzip "github.com/realTristan/hermes/compression/gzip" + "github.com/realTristan/hermes/compression/zlib" + utils "github.com/realTristan/hermes/utils" ) func main() { diff --git a/testing/fulltext/clean.go b/testing/fulltext/clean.go index 69c5e8b..41d8251 100644 --- a/testing/fulltext/clean.go +++ b/testing/fulltext/clean.go @@ -3,11 +3,11 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func clean() { - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Test CleanFT() var data = map[string]any{ @@ -24,7 +24,7 @@ func clean() { cache.FTInit(-1, -1, 3) // Search for a word in the cache - var result, _ = cache.SearchOneWord(Hermes.SearchParams{ + var result, _ = cache.SearchOneWord(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, @@ -35,7 +35,7 @@ func clean() { cache.FTClean() // Search for a word in the cache - result, _ = cache.SearchOneWord(Hermes.SearchParams{ + result, _ = cache.SearchOneWord(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, diff --git a/testing/fulltext/delete.go b/testing/fulltext/delete.go index e9fb114..bf844f2 100644 --- a/testing/fulltext/delete.go +++ b/testing/fulltext/delete.go @@ -3,11 +3,11 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func delete() { - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize the FT cache cache.FTInit(-1, -1, 3) diff --git a/testing/fulltext/ft.go b/testing/fulltext/ft.go index fa9d054..98c948d 100644 --- a/testing/fulltext/ft.go +++ b/testing/fulltext/ft.go @@ -3,11 +3,11 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func ft() { - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize the FT cache cache.FTInit(-1, -1, 3) diff --git a/testing/fulltext/main.go b/testing/fulltext/run_tests.go similarity index 100% rename from testing/fulltext/main.go rename to testing/fulltext/run_tests.go diff --git a/testing/fulltext/search.go b/testing/fulltext/search.go index 2b4f280..fdfbe83 100644 --- a/testing/fulltext/search.go +++ b/testing/fulltext/search.go @@ -3,11 +3,11 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func search() { - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize the FT cache cache.FTInit(-1, -1, 3) diff --git a/testing/fulltext/set.go b/testing/fulltext/set.go index 1e3b271..d05fc5b 100644 --- a/testing/fulltext/set.go +++ b/testing/fulltext/set.go @@ -3,11 +3,11 @@ package main import ( "fmt" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func set() { - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize the FT cache cache.FTInit(-1, -1, 3) diff --git a/nocache/testing/speed/speed.go b/testing/nocache/speed/speed.go similarity index 85% rename from nocache/testing/speed/speed.go rename to testing/nocache/speed/speed.go index a1a4117..322c084 100644 --- a/nocache/testing/speed/speed.go +++ b/testing/nocache/speed/speed.go @@ -7,13 +7,13 @@ import ( "strings" "time" - Hermes "github.com/realTristan/Hermes/nocache" + hermes "github.com/realTristan/hermes/nocache" ) -// Results: Hermes is about 40x faster than a basic search +// Results: hermes is about 40x faster than a basic search func main() { BasicSearch() - HermesSearch() + hermesSearch() } // Basic Search @@ -52,10 +52,10 @@ func BasicSearch() { } } -// Hermes Search -func HermesSearch() { +// hermes Search +func hermesSearch() { // Initialize the cache - var cache, err = Hermes.InitWithJson("../../../data/data_array.json", 3) + var cache, err = hermes.InitWithJson("../../../data/data_array.json", 3) if err != nil { panic(err) } @@ -66,7 +66,7 @@ func HermesSearch() { var start time.Time = time.Now() // Search for a word in the cache - cache.Search(Hermes.SearchParams{ + cache.Search(hermes.SearchParams{ Query: "computer", Limit: 100, Strict: false, @@ -78,7 +78,7 @@ func HermesSearch() { var averageNanos float32 = float32(average) / 100 var averageMillis float32 = averageNanos / 1000000 - fmt.Println("\nHermes: Average time is: ", averageNanos, "ns or", averageMillis, "ms") + fmt.Println("\nhermes: Average time is: ", averageNanos, "ns or", averageMillis, "ms") } // Read a json file diff --git a/testing/socket/router.go b/testing/socket/router.go index 837b139..7e065d7 100644 --- a/testing/socket/router.go +++ b/testing/socket/router.go @@ -2,13 +2,13 @@ package main import ( "github.com/gofiber/fiber/v2" - Hermes "github.com/realTristan/Hermes" - Socket "github.com/realTristan/Hermes/cloud/socket" + hermes "github.com/realTristan/hermes" + Socket "github.com/realTristan/hermes/cloud/socket" ) func main() { // Cache and fiber app - cache := Hermes.InitCache() + cache := hermes.InitCache() app := fiber.New() // Set the router diff --git a/testing/speed/func_speeds/fnspeeds.go b/testing/speed/func_speeds/fnspeeds.go index 32ba111..4648ef2 100644 --- a/testing/speed/func_speeds/fnspeeds.go +++ b/testing/speed/func_speeds/fnspeeds.go @@ -4,12 +4,12 @@ import ( "fmt" "time" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) func main() { // Cache - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() /* Initialize the FT cache if err := cache.InitFTWithJson("../../data/data_hash.json", maxWords, maxSizeBytes, schema); err != nil { @@ -55,7 +55,7 @@ func main() { // Search for a word in the cache duration("Search", func() { - var result, _ = cache.SearchOneWord(Hermes.SearchParams{ + var result, _ = cache.SearchOneWord(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, @@ -78,7 +78,7 @@ func main() { // Search for a word in the cache duration("Search", func() { - var result, _ = cache.SearchOneWord(Hermes.SearchParams{ + var result, _ = cache.SearchOneWord(hermes.SearchParams{ Query: "tristan", Limit: 100, Strict: false, diff --git a/testing/speed/redis_speed/.txt b/testing/speed/redis_speed/.txt deleted file mode 100644 index 30172d4..0000000 --- a/testing/speed/redis_speed/.txt +++ /dev/null @@ -1,6 +0,0 @@ - -Code can be found here: -https://github.com/Simpson-Computer-Technologies-Research/RediSearch - -Redisearch Speed: 40-60ms -Hermes Speed: 0.3-0.6ms diff --git a/testing/speed/search_speeds/searchspeeds.go b/testing/speed/search_speeds/searchspeeds.go index 66d8197..4a00203 100644 --- a/testing/speed/search_speeds/searchspeeds.go +++ b/testing/speed/search_speeds/searchspeeds.go @@ -7,13 +7,13 @@ import ( "strings" "time" - Hermes "github.com/realTristan/Hermes" + hermes "github.com/realTristan/hermes" ) -// Results: Hermes is about 40x faster than a basic search +// Results: hermes is about 40x faster than a basic search func main() { BasicSearch() - HermesSearch() + hermesSearch() } // Basic Search @@ -52,10 +52,10 @@ func BasicSearch() { } } -// Hermes Search -func HermesSearch() { +// hermes Search +func hermesSearch() { // Initialize the cache - var cache *Hermes.Cache = Hermes.InitCache() + var cache *hermes.Cache = hermes.InitCache() // Initialize the FT cache with a json file cache.FTInitWithJson("../../data/data_hash.json", -1, -1, 3) @@ -69,7 +69,7 @@ func HermesSearch() { start time.Time = time.Now() // Search for a word in the cache - res, _ = cache.Search(Hermes.SearchParams{ + res, _ = cache.Search(hermes.SearchParams{ Query: "computer science", Limit: 100, Strict: false, @@ -89,8 +89,8 @@ func HermesSearch() { averageNanos float64 = float64(average) / 100 averageMillis float64 = averageNanos / 1000000 ) - fmt.Println("Hermes: Average time is: ", averageNanos, "ns or", averageMillis, "ms") - fmt.Println("Hermes: Results: ", total) + fmt.Println("hermes: Average time is: ", averageNanos, "ns or", averageMillis, "ms") + fmt.Println("hermes: Results: ", total) } // Read a json file