{"id":13786702,"url":"https://github.com/twharmon/goweb","last_synced_at":"2025-05-11T22:32:08.723Z","repository":{"id":35133258,"uuid":"185477978","full_name":"twharmon/goweb","owner":"twharmon","description":"Lightweight web framework based on net/http.","archived":false,"fork":false,"pushed_at":"2022-08-30T15:51:01.000Z","size":3741,"stargazers_count":37,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-03T19:10:02.045Z","etag":null,"topics":["api","go","web","web-framework"],"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/twharmon.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}},"created_at":"2019-05-07T21:04:43.000Z","updated_at":"2024-04-05T17:45:49.000Z","dependencies_parsed_at":"2022-08-08T05:15:51.752Z","dependency_job_id":null,"html_url":"https://github.com/twharmon/goweb","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgoweb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgoweb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgoweb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgoweb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twharmon","download_url":"https://codeload.github.com/twharmon/goweb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225101370,"owners_count":17421075,"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","go","web","web-framework"],"created_at":"2024-08-03T19:01:29.486Z","updated_at":"2024-11-17T22:32:47.569Z","avatar_url":"https://github.com/twharmon.png","language":"Go","funding_links":[],"categories":["web框架","Web Frameworks","web框架`web 框架`","Web框架","Utility"],"sub_categories":["版本控制","Utility/Miscellaneous","版本控制`版本控制相关库`","实用程序/Miscellaneous","HTTP Clients","Fail injection"],"readme":"# Goweb\n\n![](https://github.com/twharmon/goweb/workflows/Test/badge.svg) [![](https://goreportcard.com/badge/github.com/twharmon/goweb)](https://goreportcard.com/report/github.com/twharmon/goweb) [![](https://gocover.io/_badge/github.com/twharmon/goweb)](https://gocover.io/github.com/twharmon/goweb)\n\nLight weight web framework based on net/http.\n\nIncludes\n- routing\n- middleware\n- logging\n\nGoweb aims to\n1. rely only on the standard library as much as possible\n2. be flexible\n3. perform well\n\n## Usage\nSee [examples](https://github.com/twharmon/goweb/tree/master/examples).\n\n### Basic\n```go\npackage main\n\nimport (\n\t\"github.com/twharmon/goweb\"\n)\n\nfunc main() {\n    app := goweb.New()\n    app.GET(\"/hello/{name}\", hello)\n    app.Run(\":8080\")\n}\n\nfunc hello(c *goweb.Context) goweb.Responder {\n    return c.JSON(http.StatusOK, goweb.Map{\n        \"hello\": c.Param(\"name\"),\n    })\n}\n```\n\n### Logging\n```go\npackage main\n\nimport (\n\t\"github.com/twharmon/goweb\"\n)\n\nfunc main() {\n    app := goweb.New()\n\tapp.RegisterLogger(newLogger(goweb.LogLevelInfo))\n    app.GET(\"/hello/{name}\", hello)\n    app.Run(\":8080\")\n}\n\nfunc hello(c *goweb.Context) goweb.Responder {\n    c.LogInfo(\"param name:\", c.Param(\"name\"))\n    // logs \"[INFO] /hello/Gopher param name: Gopher\"\n    return c.JSON(http.StatusOK, goweb.Map{\n        \"hello\": c.Param(\"name\"),\n    })\n}\n\ntype logger struct{\n\tlevel goweb.LogLevel\n}\n\nfunc newLogger(level goweb.LogLevel) goweb.Logger {\n\treturn \u0026logger{level: level}\n}\n\nfunc (l *logger) Log(c *goweb.Context, logLevel goweb.LogLevel, messages ...interface{}) {\n\tif l.level \u003e logLevel {\n\t\treturn\n\t}\n\tprefix := fmt.Sprintf(\"[%s] %s\", logLevel, c.Request.URL.Path)\n\tmessages = append([]interface{}{prefix}, messages...)\n\tlog.Println(messages...)\n}\n```\n\n### Auto TLS\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/twharmon/goweb\"\n\t\"golang.org/x/crypto/acme/autocert\"\n)\n\nfunc main() {\n\tapp := goweb.New()\n\tapp.GET(\"/\", func(c *goweb.Context) goweb.Responder {\n\t\treturn c.JSON(http.StatusOK, goweb.Map{\n\t\t\t\"hello\": \"world\",\n\t\t})\n\t})\n\tserveTLS(app)\n}\n\nfunc serveTLS(app *goweb.Engine) {\n\tm := \u0026autocert.Manager{\n\t\tCache:  autocert.DirCache(\".certs\"),\n\t\tPrompt: autocert.AcceptTOS,\n\t\tHostPolicy: func(_ context.Context, host string) error {\n\t\t\tif host == \"example.com\" {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\treturn errors.New(\"host not configured\")\n\t\t},\n\t}\n\tgo http.ListenAndServe(\":http\", m.HTTPHandler(nil))\n\ts := \u0026http.Server{\n\t\tAddr:      \":https\",\n\t\tTLSConfig: m.TLSConfig(),\n\t\tHandler:   app,\n\t}\n\tlog.Fatalln(s.ListenAndServeTLS(\"\", \"\"))\n}\n```\n\n### Easily extendable\nSee [serving files](https://github.com/twharmon/goweb/tree/master/examples/files), [template rendering](https://github.com/twharmon/goweb/tree/master/examples/templates), [tls](https://github.com/twharmon/goweb/tree/master/examples/tls), and [logging](https://github.com/twharmon/goweb/tree/master/examples/logging) for examples.\n\n## Documentation\nFor full documentation see [pkg.go.dev](https://pkg.go.dev/github.com/twharmon/goweb).\n\n## Benchmarks\n```\nBenchmarkGinPlaintext-10         \t 2706439\t       440.0 ns/op\t    1040 B/op\t       9 allocs/op\nBenchmarkEchoPlaintext-10        \t 2549317\t       470.7 ns/op\t    1024 B/op\t      10 allocs/op\nBenchmarkGowebPlaintext-10       \t 1584044\t       756.6 ns/op\t    1456 B/op\t      16 allocs/op\nBenchmarkGorillaPlaintext-10     \t 1000000\t      1027 ns/op\t    1744 B/op\t      17 allocs/op\nBenchmarkMartiniPlaintext-10     \t  223416\t      5364 ns/op\t    1789 B/op\t      39 allocs/op\n\nBenchmarkGowebJSON-10            \t   25945\t     46359 ns/op\t   50905 B/op\t      15 allocs/op\nBenchmarkEchoJSON-10             \t   25664\t     46571 ns/op\t   50641 B/op\t      10 allocs/op\nBenchmarkGorillaJSON-10          \t   25716\t     46857 ns/op\t   51115 B/op\t      16 allocs/op\nBenchmarkGinJSON-10              \t   23697\t     50697 ns/op\t  100836 B/op\t      10 allocs/op\nBenchmarkMartiniJSON-10          \t   22746\t     52613 ns/op\t   52665 B/op\t      41 allocs/op\n\nBenchmarkGinPathParams-10        \t  914139\t      1273 ns/op\t    1849 B/op\t      25 allocs/op\nBenchmarkEchoPathParams-10       \t  889014\t      1309 ns/op\t    1865 B/op\t      25 allocs/op\nBenchmarkGowebPathParams-10      \t  627306\t      1902 ns/op\t    2570 B/op\t      33 allocs/op\nBenchmarkGorillaPathParams-10    \t  552852\t      2144 ns/op\t    2874 B/op\t      32 allocs/op\nBenchmarkMartiniPathParams-10    \t  188500\t      6215 ns/op\t    2641 B/op\t      47 allocs/op\n```\n\n## Contribute\nCreate a pull request to contribute to Goweb.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fgoweb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwharmon%2Fgoweb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fgoweb/lists"}