{"id":15272425,"url":"https://github.com/najibulloshapoatov/server-core","last_synced_at":"2026-01-05T05:06:33.656Z","repository":{"id":39953362,"uuid":"484987004","full_name":"najibulloShapoatov/server-core","owner":"najibulloShapoatov","description":"Server library provides a complete HTTP/HTTPS server that can be easily embedded in your application and requires minimum to no configuration, being able to run securely with its default settings.","archived":false,"fork":false,"pushed_at":"2023-05-15T14:09:30.000Z","size":318,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-27T19:28:49.102Z","etag":null,"topics":["api","api-rest","dynamic-router","echo","echo-alternative","gin","gin-alternative","gin-gonic","go","golang","golang-api","golang-native-server","golang-server","https-server","mux","mux-alternative","mux-router","router","routing","server-core"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/najibulloShapoatov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-04-24T09:48:34.000Z","updated_at":"2022-05-02T18:56:23.000Z","dependencies_parsed_at":"2022-09-26T16:20:40.693Z","dependency_job_id":"599400a1-8605-4070-8c0e-31326e317507","html_url":"https://github.com/najibulloShapoatov/server-core","commit_stats":{"total_commits":14,"total_committers":3,"mean_commits":4.666666666666667,"dds":0.3571428571428571,"last_synced_commit":"cb6d2b9825bcb1bfa1249682eba4a7e351ff6aea"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fserver-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fserver-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fserver-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/najibulloShapoatov%2Fserver-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/najibulloShapoatov","download_url":"https://codeload.github.com/najibulloShapoatov/server-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244990069,"owners_count":20543614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-rest","dynamic-router","echo","echo-alternative","gin","gin-alternative","gin-gonic","go","golang","golang-api","golang-native-server","golang-server","https-server","mux","mux-alternative","mux-router","router","routing","server-core"],"created_at":"2024-09-30T09:06:48.539Z","updated_at":"2026-01-05T05:06:33.625Z","avatar_url":"https://github.com/najibulloShapoatov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Server\nServer library provides a complete HTTP/HTTPS server that can be easily embedded in your application and\nrequires minimum to no configuration, being able to run securely with its default settings.\n\n### see example [server-core-example](https://github.com/najibulloShapoatov/server-core-example) repository\n\nhttps://pkg.go.dev/github.com/najibulloShapoatov/server-core\n\n#### Features\n- Automatic routing\n- Auto acquire HTTPS certificates through Let's Encrypt\n- Session management with support for different stores (DB, Redis, In-Memory built in stores)\n- Support for various input/output encodings (JSON, XML, Binary, gRPC built in)\n- Support for various compression algorithms (GZip, Deflate, Brotli built in)\n- Access logs (Apache format compatible)\n- Security enhancements (XSS, CSRF, DNT, HSTS, CSP, BruteForce, Rate Limiter, Whitelist/Blacklist built in)\n- Request tracing\n- Server statistics\n- Internationalization and GeoIP detection support\n\n### Install\n\n```bash\n$ go get github.com/najibulloShapoatov/server-core/server\n```\n\n### Usage example(s)\n\n\n##### Start a server that listens on HTTP(80)\n```go\nimport (\n   \"github.com/najibulloShapoatov/server-core/server\"\n)\n\nfunc main() {\n    svc := server.New(nil)\n    svc.Start()\n}\n```\n\n##### Register custom stores and engines\n```go\n// register 2 new middleware functions\nserver.UseMiddleware(m1, m2) \n\n// register decoder/encoder for some custom content type\nserver.RegisterDecoder(\"text/yaml\", myYAMLDecoder)\nserver.RegisterEncoder(\"text/yaml\", myYAMLEncoder)\n\n// register http endpoints for all your module handlers\nserver.RegisterRoute(myService)\n\n\n```\n\n# Configuration library\n\nAllows the application to load it's configuration from `.config` files or environment variables\n\n## Install\n\nTo install the platform\n\n```\n$ go get github.com/najibulloShapoatov/server-core/settings\n```\n\n## Usage example\n\n```go\nimport \"github.com/najibulloShapoatov/server-core/settings\"\n\ntype MySettings struct {\n    Host    string        `config:\"app.host\" default:\"localhost\"`\n    Port    int           `config:\"app.port\" default:\"80\"`\n    Timeout time.Duration `config:\"app.timeout\" default:\"3s\"`\n    Debug   bool          `config:\"debug\" default:\"on\"`\n    \n}\n\nfunc main() {\n\n   s := settings.GetSettings()\n   err := s.Load(\n         settings.NewFileLoader(\"file.conf\", false),  // load config from this file\n         settings.NewEnvLoader(false, \"app\")          // and also from environment variables\n   )\n   if err != nil {\n       fmt.Prinln(\"failed to parse settings\", err)\n   }\n\n   // unmarshall directly into a struct\n   var mySettings MySettings\n   if err := settings.Unmarshal(\u0026mySettings); err != nil {\n       fmt.Println(\"some error\", err)\n   }\n\n   // retrieve a value by name\n   isDebug, exists := settings.GetBool(\"debug\")\n}\n\n```\n\n## Configuration files\n\nConfiguration files are mostly `key=value` files but with few additions. For example, numbers are evaluated by the parser and booleans can be all truthy values besides true or false. Other files can be included using the `include` directive\n\n```bash\n# String values\nkey.name = \"value\" # this is inline comment\nkey.multiline = \"multi \\\nline \\\nstring\"\n\n# Number values\ntest.int.value = 5\ntest.float.value = 3.14\ntest.negative.value = -1.2\ntest.hex.number = 0x1234 # will parse to 4660\ntest.octal.number = 0o123 # will parse to 83\ntest.binary.number = 0b1010101 # will parse to 85\ntest.exponential.number = 1e3 # will parse to 1000\ntest.negative.exponential.number = 2e-2 # will parse to 0.02\n\n# Boolean values\ntest.bool.value1 = yes       # or no\ntest.bool.value2 = on        # or off\ntest.bool.value3 = set       # or unset\ntest.bool.value4 = active    # or inactive\ntest.bool.value5 = enabled   # or disabled\ntest.bool.value6 = true      # or false\ntest.bool.value6 = 1         # or 0\n\n# Duration\ntest.duration.value1 = \"1h5m\"\ntest.duration.value2 = \"3s\"\n\n# Include other file\ninclude \"sub-config-file.conf\"\n```\n\n\n# cache\nCache library with cache manager.\n\n\u003e All cache driver implemented the cache.Cache interface. So, You can add any custom driver.\n\n**Supported Drivers:**\n\n- `redis`  by `github.com/go-redis/redis`\n- `memCached` by `github.com/bradfitz/gomemcache/memcache`\n- `freeCache` by `github.com/coocood/freecache`\n- `bigCache`  by `github.com/allegro/bigcache`\n\n## Install\n\n```bash\ngo get github.com/najibulloShapoatov/server-core/cache\n```\n\nYou can also install individual drivers\n```bash\ngo get github.com/najibulloShapoatov/server-core/cache/bigcache\n```\n\n## Cache Interface\n\nAll cache driver implemented the cache.Cache interface. So, You can add any custom driver.\n\n```go\n// Cache interface definition\ntype Cache interface {\n\tType() string\n\t// Retrieve value at key from cache\n\tGet(key string, value interface{}) (err error)\n\t// Checks if key is available in cache\n\tHas(key string) (ok bool)\n\t// Stores a key with a given life time. 0 for permanent\n\tSet(key string, value interface{}, ttl time.Duration) (err error)\n\t// Remove a key by name\n\tDel(key string) (err error)\n\t// List all available cache keys\n\tKeys(pattern string) (available []string)\n\t// Removes all keys\n\tClear()\n}\n```\n\n## Usage example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/allegro/bigcache\"\n\tbigcachecore \"github.com/najibulloShapoatov/server-core/cache/bigcache\"\n\t\"github.com/najibulloShapoatov/server-core/cache/freecache\"\n\t\"github.com/najibulloShapoatov/server-core/cache/memcache\"\n\t\"github.com/najibulloShapoatov/server-core/core/cache\"\n\t\"github.com/najibulloShapoatov/server-core/core/cache/redis\"\n\t\"time\"\n)\n\n// change package main\nfunc main() {\n\tredisCfg := redis.Config{Addr: \"0.0.0.0:6379\", Password: \"\"}\n\tredisClient := redis.New(\u0026redisCfg)\n\tmemCacheCfg := memcache.Config{Addr: \"127.0.0.1:11211\"}\n\tmemCacheClient := memcache.New(\u0026memCacheCfg)\n\tfreeCacheCfg := freecache.Config{}\n\tfreeCacheClient := freecache.New(\u0026freeCacheCfg)\n\tbigCacheCfg := bigcache.DefaultConfig(5 * time.Second)\n\tbigCacheClient := bigcachecore.New(\u0026bigCacheCfg)\n\n\t// register one(or some) cache driver\n\n\tcache.Register(cache.Redis, redisClient)\n\tcache.Register(cache.MemCache, memCacheClient)\n\tcache.Register(cache.FreeCache, freeCacheClient)\n\tcache.Register(cache.BigCache, bigCacheClient)\n\tcache.DefaultUse(cache.Redis)\n\tfor i := 0; i \u003c 10; i++ {\n\t\tkey := fmt.Sprintf(\"testm-%d\", i)\n\t\tvalue := []byte(fmt.Sprintf(\"value-%d\", i))\n\n\t\terr := cache.Set(key, value, 5)\n\t\tfmt.Println(err)\n\t}\n\tvar rez []byte\n\t_ = cache.Get(\"test-77\", \u0026rez)\n\tfmt.Println(rez)\n\tcache.DefaultUse(cache.BigCache)\n\tkey := fmt.Sprintf(\"testm-%d\", 99)\n\tvalue := []byte(fmt.Sprintf(\"value-%d\", 48777772788))\n\t_ = cache.Set(key, value, 60)\n\t_ = cache.Get(\"testm-99\", \u0026rez)\n\tfmt.Println(\"BC:\", rez)\n\tfc := cache.Driver(cache.FreeCache)\n\tkeyb := fmt.Sprintf(\"testdriver-%d\", 611011010)\n\tvalueb := []byte(fmt.Sprintf(\"valuedriver-%d\", 611011010))\n\terr := fc.Set(keyb, valueb, 0)\n\tfmt.Println(\"ERR:\", err)\n\tvar fcr []byte\n\t_ = fc.Get(\"test-611011010\", \u0026fcr)\n\tfmt.Println(\"FC:\", \u0026fcr)\n\n}\n```\n# Cluster\n\nAllows communication and synchronization between cluster nodes\n\n## Install\n\nTo install the library\n\n```\n$ go get github.com/najibulloShapoatov/server-core/cluster\n```\n\n## Usage example\n\n```go\n\nc, err := cluster.Join(\"cluster-name\")\n\n// Listen for cluster messages\nc.OnMessage(func(msg *cluster.Message) {\n   // handle message from other nodes\n})\n\n// send a message to all nodes in the cluster\nc.Broadcast(message)\n\n// Obtain a mutex lock in the cluster\nerr := c.Lock(\"lock-name\")\nif err != nil {\n    // Mutex is already lock by another node\n}\n\n// ...\n// Perform action\n// ...\n\n// release lock \nc.Unlock(\"lock-name\")\n\n// Leave the cluster\nc.Leave()\n\n```\n\n\n# Scheduler library\n\nAllows the application to run background jobs.\n\n## Install\n\nTo install the library\n\n```\n$ go get github.com/najibulloShapoatov/server-core/scheduler\n``` \n\n## Usage example\n\n```go\ntask := Task{\n\tName:     \"task 1\",\n\tSpec:     \"* * * * * *\",\n\tMaxRetry: 3,\n\tJob: func() (err error) {\n\t    // Do something\n\t    return err\n\t},\n}\nerr := RegisterJob(\u0026task)\n\nif err != nil {\n    UnregisterJob(\u0026task)\n}\n```\n\n###Cron Expression Format\n\n```\nField name   | Mandatory? | Allowed values  | Allowed special characters\n----------   | ---------- | --------------  | --------------------------\nSeconds      | Yes        | 0-59            | * / , -\nMinutes      | Yes        | 0-59            | * / , -\nHours        | Yes        | 0-23            | * / , -\nDay of month | Yes        | 1-31            | * / , - ?\nMonth        | Yes        | 1-12 or JAN-DEC | * / , -\nDay of week  | Yes        | 0-6 or SUN-SAT  | * / , - ?\n\n* : every\n, : multiple values\n- : ranges\n? : can be used for leaving Day Of month or Day of week blank\n```\n\n###Predefined schedules\n```\nEntry                  | Description                                | Equivalent To\n-----                  | -----------                                | -------------\n@yearly (or @annually) | Run once a year, midnight, Jan. 1st        | 0 0 0 1 1 *\n@monthly               | Run once a month, midnight, first of month | 0 0 0 1 * *\n@weekly                | Run once a week, midnight between Sat/Sun  | 0 0 0 * * 0\n@daily (or @midnight)  | Run once a day, midnight                   | 0 0 0 * * *\n@hourly                | Run once an hour, beginning of hour        | 0 0 * * * *\n@every \u003cduration\u003e      | Run every time specified, eg: @every 1h30m |\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnajibulloshapoatov%2Fserver-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnajibulloshapoatov%2Fserver-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnajibulloshapoatov%2Fserver-core/lists"}