{"id":27885845,"url":"https://github.com/nexcode/wenex","last_synced_at":"2025-05-05T07:47:57.960Z","repository":{"id":49094380,"uuid":"68080385","full_name":"nexcode/wenex","owner":"nexcode","description":"Simple and fast web framework for Go","archived":false,"fork":false,"pushed_at":"2025-01-17T12:18:17.000Z","size":52,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-17T13:31:31.279Z","etag":null,"topics":["go","golang","web","webframework"],"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/nexcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-13T06:19:07.000Z","updated_at":"2025-01-17T12:17:19.000Z","dependencies_parsed_at":"2023-11-16T20:16:32.339Z","dependency_job_id":"c766db87-322b-4491-937d-5705752d0b94","html_url":"https://github.com/nexcode/wenex","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexcode%2Fwenex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexcode%2Fwenex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexcode%2Fwenex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nexcode%2Fwenex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nexcode","download_url":"https://codeload.github.com/nexcode/wenex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252463266,"owners_count":21751757,"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":["go","golang","web","webframework"],"created_at":"2025-05-05T07:47:56.072Z","updated_at":"2025-05-05T07:47:57.953Z","avatar_url":"https://github.com/nexcode.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wenex\n\n[![GoDoc](https://godoc.org/github.com/nexcode/wenex?status.svg)](https://pkg.go.dev/github.com/nexcode/wenex)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nexcode/wenex)](https://goreportcard.com/report/github.com/nexcode/wenex)\n\nSimple and fast web framework for Go\n\n## Table of Contents\n\n* [Build Status](https://travis-ci.org/nexcode/wenex)\n* [GoDoc Reference](https://godoc.org/github.com/nexcode/wenex)\n* [Requirements](#requirements)\n* [Quick Start](#quick-start)\n  * [Download and Install](#download-and-install)\n  * [Simple Example](#simple-example)\n* [Starting the webserver](#starting-the-webserver)\n* [Configuration options](#configuration-options)\n* [Work with config file](#work-with-config-file)\n* [Routing configuration](#routing-configuration)\n* [Work with logger](#work-with-logger)\n\n## Requirements\n\n    Go \u003e= 1.17\n\n## Quick Start\n\n#### Download and Install\n\n    go get -u github.com/nexcode/wenex\n\n#### Simple Example\n\n```go\npackage main\n\nimport (\n\t\"io\"\n\t\"net/http\"\n\n\t\"github.com/nexcode/wenex\"\n)\n\nfunc first(w http.ResponseWriter, r *http.Request) {\n\tio.WriteString(w, \"Hello,\")\n\twenex.GetRun(r.Context()).Next()\n\tio.WriteString(w, \"!\")\n}\n\nfunc second(w http.ResponseWriter, r *http.Request) {\n\tio.WriteString(w, \" World\")\n}\n\nfunc main() {\n\tconfig := wenex.DefaultConfig()\n\tconfig[\"server.http.listen\"] = \":8080\"\n\n\twnx, err := wenex.New(\"simpleapp\", config, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif err = wnx.Router.StrictRoute(\"/\", \"HEAD\", \"GET\").Chain(first, second); err != nil {\n\t\tpanic(err)\n\t}\n\n\twnx.Logger(\"info\").Print(\"running application...\")\n\n\tif err = wnx.Run(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\nOpen your browser and visit `http://localhost:8080`\n\n## Starting the webserver\n\nIn its simplest form, a webserver can be started like this:\n\n```go\nconfig := wenex.DefaultConfig()\nconfig[\"server.http.listen\"] = \":8080\"\n\nwnx, err := wenex.New(\"simpleapp\", config)\nif err != nil {\n\tpanic(err)\n}\n\n// define routing and something else...\n\nif err = wnx.Run(); err != nil {\n\tpanic(err)\n}\n```\n\nIn this simple example:  \n`server.http.listen` - port that will listen to the webserver  \n`simpleapp` - name of the application (a `simpleapp.conf` file will be created in the working directory)  \n`config` - configuration options\n\n## Configuration options\n\n* `server.gzip.enable` - enables and disables gzip\n* `server.gzip.level` - gzip compression level\n* `server.http.listen` - port that will listen to http traffic\n* `server.https.listen` - port that will listen to TLS (https) traffic\n* `server.https.stringCert.cert` - string containing certificate\n* `server.https.stringCert.key` - string containing private key\n* `server.https.loadCert.cert` - file containing certificate\n* `server.https.loadCert.key` - file containing private key\n* `server.https.autoCert.hosts` - array of domains\n* `server.https.autoCert.dirCache` - cache directory\n* `server.timeout.read` - connection read timeout\n* `server.timeout.write` - connection write timeout\n* `server.timeout.idle` - connection idle timeout\n* `logger.defaultName` - log filename for empty logger\n* `logger.namePrefix` - prefix that will be added to all saved log files.\n\tFor example, if you use `log/` prefix, then all logs files will be in `log/` folder\n* `logger.useFlag` - sets the output flags for the logger. The flag bits are Ldate, Ltime, and so on\n* `logger.usePrefix` - string that will be added at the beginning of each message\n\n## Work with config file\n\nIf you run wenex with this config:\n```go\nconfig := wenex.DefaultConfig()\n\nwnx, err := wenex.New(\"simpleapp\", config)\nif err != nil {\n\tpanic(err)\n}\n\n// Some code and wnx.Run()\n```\n\nA config file (`simpleapp.conf`) appears in the working directory.  \nFrom the `config` variable, only missing values will be written to the file.  \nOverwriting existing values will not occur.\n```json\n{\n    \"log\": {\n        \"filePrefix\": \"log/\"\n    },\n    \"server\": {\n        \"http\": {\n            \"listen\": \":http\"\n        },\n        \"timeout\": {\n            \"idle\": \"30s\",\n            \"read\": \"30s\",\n            \"write\": \"30s\"\n        }\n    }\n}\n```\n\nYou can add any parameters directly to the file or use api:\n```go\nwnx.Config.Set(\"key1.key2.keyN\", 1000)\nerr := wnx.Config.Save()\n```\n\nAfter this, the config file will look like this:\n```json\n{\n    \"key1\": {\n        \"key2\": {\n            \"keyN\": 1000\n        }\n    },\n    \"log\": {\n        \"filePrefix\": \"log/\"\n    },\n    \"server\": {\n        \"http\": {\n            \"listen\": \":http\"\n        },\n        \"timeout\": {\n            \"idle\": \"30s\",\n            \"read\": \"30s\",\n            \"write\": \"30s\"\n        }\n    }\n}\n```\n\nYou can get the value of the parameters by api:\n```go\nvalueF64, err := wnx.Config.Float64(\"key1.key2.keyN\")\n// Or use it (panic on type error):\n// value := wnx.Config.MustFloat64(\"key1.key2.keyN\")\n\nvalueStr, err := wnx.Config.String(\"server.http.listen\")\n// Or use it (panic on type error):\n// value := wnx.Config.MustString(\"server.http.listen\")\n\n// You can get the value as an interface{}\nvalueInterface := wnx.Config.Get(\"key\")\n```\n\n## Routing configuration\n\nFor the routing declaration in wenex two methods are used:\n* `wnx.Router.StrictRoute(pattern, methods)` - tied to the end of pattern\n* `wnx.Router.WeakRoute(pattern, methods)` - not tied to the end of pattern\n\nWenex supports the following special constructs in the pattern:\n* `*` - a sequence of any characters, including the empty string\n* `:name` - value of this path element will be available as a value of a get-variable with the same name\n\nRouting declaration returns a method, that allows you to specify multiple handlers:  \n`wnx.Router.StrictRoute(pattern, methods).Chain(handler1, handler2, handlerN)`\n\nMatching examples:\n```go\nwnx.Router.StrictRoute(\"/*/:var/test/\", \"HEAD\", \"GET\").Chain(...)\n// matching requests:\n// /sefsef/aaa/test/\n// /zzz/qwe/test/\n\nwnx.Router.WeakRoute(\"/*/:var/test/\", \"HEAD\", \"GET\").Chain(...)\n// matching requests:\n// /sefsef/aaa/test/\n// /zzz/zxc/test/rrr/\n// /zzz/gg/test/ppp/fff\n```\n\nChains can run completely sequentially, or you can call the next chain before the first one has completed.  \nFor this, the `Next()` method is used.  \nAn example of this behavior is given in the section [Simple Example](#simple-example).\n\n## Work with logger\n\nWinx creates files with logs dynamically.  \nIt use `log.filePrefix` fo path prefix fo all logs files.  \nFor example:\n```go\nwnx.Logger(\"file1\").Print(\"some data...\")\nwnx.Logger(\"folder2/file2\").Print(\"some data...\")\n\n// default log file:\nwnx.Logger(\"\").Print(\"some data...\")\n```\nYou can customize the logger in accordance with the std `log.logger` api:\n```go\nwnx.Logger(\"\").SetPrefix(\"prefix\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexcode%2Fwenex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnexcode%2Fwenex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnexcode%2Fwenex/lists"}