{"id":36873409,"url":"https://github.com/xfali/neve-web","last_synced_at":"2026-01-12T15:03:53.045Z","repository":{"id":57544246,"uuid":"296061524","full_name":"xfali/neve-web","owner":"xfali","description":"neve的WEB扩展组件，用于集成WEB相关服务。","archived":false,"fork":false,"pushed_at":"2021-10-11T14:09:22.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-27T16:15:31.357Z","etag":null,"topics":["web"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xfali.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":"2020-09-16T14:44:07.000Z","updated_at":"2021-10-11T14:05:47.000Z","dependencies_parsed_at":"2022-09-16T23:02:05.727Z","dependency_job_id":null,"html_url":"https://github.com/xfali/neve-web","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"purl":"pkg:github/xfali/neve-web","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fneve-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fneve-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fneve-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fneve-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xfali","download_url":"https://codeload.github.com/xfali/neve-web/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fneve-web/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28340416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"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":["web"],"created_at":"2026-01-12T15:03:48.835Z","updated_at":"2026-01-12T15:03:53.036Z","avatar_url":"https://github.com/xfali.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# neve-web\n\nneve-web是neve的WEB扩展组件，用于集成WEB相关服务。\n\n内置WEB中间件为[gin](https://github.com/gin-gonic/gin)\n\n## 安装\n```\ngo get github.com/xfali/neve-web\n```\n\n## 使用\n  \n### 1. neve集成（依赖[neve-core](https://github.com/xfali/neve-core)）\n```\napp := neve.NewFileConfigApplication(\"assets/config-test.yaml\")\napp.RegisterBean(neveweb.NewGinProcessor())\n// 或者\n// app.RegisterBean(gineve.NewProcessor())\n//注册值注入处理器，用于根据配置注入值（非必须）\napp.RegisterBean(processor.NewValueProcessor())\n//注册其他对象\napp.RegisterBean(\u0026testProcess{})\napp.RegisterBean(\u0026webBean{})\napp.Run()\n```\n\n### 2. 配置\n在config-example.yaml中配置示例如下：\n```\nneve:\n  web:\n    log:\n      requestHeader: true\n      requestBody: true\n      responseHeader: true\n      responseBody: true\n      level: \"warn\"\n\n    server:\n      contextPath: \"\"\n      host: \"\"\n      port: 8080\n      tls:\n        cert: \n        key:\n      readTimeout: 15\n      writeTimeout: 15\n      idleTimeout: 15\n```\n* 【neve.web.log】配置rest的日志输出，包含request header、body，response header、body以及配置日志级别，根据项目需要进行配置。\n* 【neve.web.server】配置WEB服务的端口、读写超时等配置，contextPath配置总的根路由路径，如contextPath: \"/order\"\n* 【neve.web.server.tls】https tls相关配置\n\n### 3. 注册路由\n注册的bean实现 HttpRoutes(engine gin.IRouter)方法\n```\n//webBean通过app.RegisterBean(\u0026webBean{})注册，并实现下列方法：\n\nfunc (b *webBean) HttpRoutes(engine gin.IRouter) {\n\tengine.GET(\"test\", b.HttpLogger.LogHttp(), func(context *gin.Context) {\n\t\tcontext.JSON(http.StatusOK, result.Ok(b.V))\n\t})\n\n\tengine.POST(\"test\", b.HttpLogger.LogHttp(), func(context *gin.Context) {\n\t\td, err := context.GetRawData()\n\t\tif err != nil {\n\t\t\tcontext.AbortWithStatus(http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\tcontext.JSON(http.StatusOK, result.Ok(string(d)))\n\t})\n}\n```\n\n### 4. 输出日志配置\n注入loghttp.HttpLogger，在gin.IRouter中添加该handler\n```\ntype webBean struct {\n\tV          string //`fig:\"Log.Level\"`\n\t//注入\n\tHttpLogger loghttp.HttpLogger `inject:\"\"`\n}\nfunc (b *webBean) HttpRoutes(engine gin.IRouter) {\n    //使用“b.HttpLogger.LogHttp()”配置，作为首个handler\n\tengine.GET(\"test\", b.HttpLogger.LogHttp(), func(context *gin.Context) {\n\t\tcontext.JSON(http.StatusOK, result.Ok(b.V))\n\t})\n}\n```\n\n### 5. 注册全局过滤器\n1. 注册的bean实现 FilterHandler(ctx *gin.Context) 方法\n```\ntype filter struct{}\n\nfunc (f *filter) FilterHandler(context *gin.Context) {\n    if f.pass() {\n        // 继续执行\n        context.Next()\n    } else {\n        // 过滤并阻断\n        context.Abort()\n    }\n}\n```\n过滤器执行的顺序遵循bean注册的先后顺序\n\n2. 通过NewProcessor时添加过滤器\n```\napp.RegisterBean(gineve.NewProcessor(gineve.OptAddFilters(func(context *gin.Context) {\n\t\tcontext.Set(\"hello\", \"world\")\n\t\tcontext.Next()\n\t})))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fneve-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxfali%2Fneve-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fneve-web/lists"}