{"id":15462915,"url":"https://github.com/funswe-zz/flow","last_synced_at":"2026-05-24T12:01:47.939Z","repository":{"id":45245767,"uuid":"187772433","full_name":"funswe-zz/flow","owner":"funswe-zz","description":"golang web frame as like koajs","archived":false,"fork":false,"pushed_at":"2024-12-02T12:53:53.000Z","size":151,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-17T04:06:54.214Z","etag":null,"topics":["golang","koajs","web"],"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/funswe-zz.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":"2019-05-21T06:09:17.000Z","updated_at":"2024-12-02T12:53:18.000Z","dependencies_parsed_at":"2025-02-08T00:51:12.509Z","dependency_job_id":"bb3b20e8-f340-4484-a87c-d9b27af95dc6","html_url":"https://github.com/funswe-zz/flow","commit_stats":null,"previous_names":["funswe-zz/flow"],"tags_count":122,"template":false,"template_full_name":null,"purl":"pkg:github/funswe-zz/flow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funswe-zz%2Fflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funswe-zz%2Fflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funswe-zz%2Fflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funswe-zz%2Fflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funswe-zz","download_url":"https://codeload.github.com/funswe-zz/flow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funswe-zz%2Fflow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29201117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T16:28:23.579Z","status":"ssl_error","status_checked_at":"2026-02-07T16:28:22.566Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","koajs","web"],"created_at":"2024-10-02T00:06:00.852Z","updated_at":"2026-02-07T17:32:04.775Z","avatar_url":"https://github.com/funswe-zz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flow\nflow是一个golang的web框架，使用koajs的洋葱圈中间件模型，框架内置了Orm，Redis，HttpClient，Jwt等工具，得益于[httprouter](https://github.com/julienschmidt/httprouter) ,性能提高30倍\n\n# 安装\n- go get -u github.com/funswe/flow\n\n# Server配置\n```\ntype ServerConfig struct {\n\tAppName    string // 应用名称，默认值flow\n\tProxy      bool   // 是否是代理模式，默认值false\n\tHost       string // 服务启动地址，默认值127.0.0.1\n\tPort       int    // 服务端口，默认值9505\n\tStaticPath string // 服务器静态资源路径，默认值当前目录下的statics\n}\n```\n# Logger配置\n日志使用的是[logrus](https://github.com/sirupsen/logrus) ，使用[rotatelogs](https://github.com/lestrrat-go/file-rotatelogs) 按日期分割日志\n```\ntype LoggerConfig struct {\n\tLoggerLevel string // 日志级别，默认值debug\n\tLoggerPath  string // 日志存放目录，默认值当前目录下的logs\n}\n```\n# Orm配置\norm框架使用的是[gorm](https://github.com/go-gorm/gorm) ，暂时只支持mysql\n```\ntype OrmConfig struct {\n\tEnable   bool // 是否启用orm，默认值false\n\tUserName string // 数据库用户名\n\tPassword string // 数据库密码\n\tDbName   string // 数据库名\n\tHost     string // 数据库地址，默认值127.0.0.1\n\tPort     int // 数据库端口，默认值3306\n\tPool     *OrmPool // 数据库连接池相关配置\n}\n\ntype OrmPool struct {\n\tMaxIdle         int // 连接池最大空闲链接，默认值5\n\tMaxOpen         int // 连接池最大连接数，默认值10\n\tConnMaxLifeTime int64 // 连接最长存活期，超过这个时间连接将不再被复用，单位秒，默认值25000\n\tConnMaxIdleTime int64 // 连接池里面的连接最大空闲时长，单位秒，默认值10\n}\n```\n# Redis配置\nredis使用的是[go-redis](https://github.com/go-redis/redis/v8)\n```\ntype RedisConfig struct {\n\tEnable   bool // 是否启用redis，默认值false\n\tPassword string // redis的密码\n\tDbNum    int // redis的库，默认值0\n\tHost     string // redis的地址，默认值127.0.0.1\n\tPort     int // redis的端口，默认值6379\n\tPrefix   string // redis的key前缀，默认值flow\n}\n```\n# HttpClient配置\nhttpclient使用的是[go-resty](https://github.com/go-resty/resty/v2)\n```\ntype CurlConfig struct {\n\tTimeout time.Duration     // 请求的超时时间，单位秒，默认值10\n\tHeaders map[string]string // 统一请求的头信息\n}\n```\n# Jwt配置\njwt使用的是[jwt-go](https://github.com/golang-jwt/jwt)\n```\ntype JwtConfig struct {\n\tTimeout   time.Duration // 请求的超时时间，单位小时，默认值24\n\tSecretKey string        // 秘钥\n}\n```\n# 跨域配置\n```\ntype CorsConfig struct {\n\tEnable         bool // 是否开启跨域支持\n\tAllowOrigin    string // 跨域支持的域，默认值*\n\tAllowedHeaders string // 跨域支持的头\n\tAllowedMethods string // 跨域支持的请求方法，默认值GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE\n}\n```\n# 示例\n## 1、返回文本\n```\nfunc main() {\n\tflow.GET(\"/hello\", func(ctx *flow.Context) {\n\t\tctx.Body(\"hello, flow\")\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n启动程序，在浏览器里访问http://localhost:9505/hello ,可以看到浏览器返回hello, flow\n## 2、返回json\n```\nfunc main() {\n\tflow.GET(\"/json\", func(ctx *flow.Context) {\n\t\tctx.Json(map[string]interface{}{\n\t\t\t\"msg\": \"hello, flow\",\n\t\t})\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n启动程序，在浏览器里访问http://localhost:9505/json ,可以看到浏览器返回json字符串：{\"msg\": \"hello, flow\"}，Content-Type: application/json; charset=utf-8\n## 3、获取请求参数\n```\nfunc main() {\n\tflow.GET(\"/param/:name\", func(ctx *flow.Context) {\n\t\tname := ctx.GetStringParam(\"name\")\n\t\tage := ctx.GetIntParam(\"age\")\n\t\tctx.Json(map[string]interface{}{\n\t\t\t\"name\": name,\n\t\t\t\"age\":  age,\n\t\t})\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n## 4、绑定参数\n```\nfunc main() {\n\tparam := struct {\n\t\tName string\n\t\tAge  int\n\t}{}\n\tflow.GET(\"/param/:name\", func(ctx *flow.Context) {\n\t\terr := ctx.Parse(\u0026param)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tctx.Json(map[string]interface{}{\n\t\t\t\"name\": param.Name,\n\t\t\t\"age\":  param.Age,\n\t\t})\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n## 5、中间件使用\n```\nfunc main() {\n\tflow.Use(func(ctx *flow.Context, next flow.Next) {\n\t\tfmt.Println(\"mid1-\u003estart,time==\", time.Now().UnixNano())\n\t\tnext()\n\t\tfmt.Println(\"mid1-\u003eend,time===\", time.Now().UnixNano())\n\t})\n\tflow.Use(func(ctx *flow.Context, next flow.Next) {\n\t\tfmt.Println(\"mid2-\u003estart,time==\", time.Now().UnixNano())\n\t\tnext()\n\t\tfmt.Println(\"mid2-\u003eend,time===\", time.Now().UnixNano())\n\t})\n\tflow.GET(\"/middleware\", func(ctx *flow.Context) {\n\t\tctx.Body(\"middleware\")\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n## 6、文件下载\n```\nfunc main() {\n\tflow.GET(\"/download\", func(ctx *flow.Context) {\n\t\tctx.Download(\"test-file.zip\")\n\t})\n\tlog.Fatal(flow.Run())\n}\n```\n\n# [更多例子](https://github.com/funswe/flow-example)\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunswe-zz%2Fflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunswe-zz%2Fflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunswe-zz%2Fflow/lists"}