{"id":13613545,"url":"https://github.com/Justice-love/go-aspect","last_synced_at":"2025-04-13T15:33:17.355Z","repository":{"id":144270707,"uuid":"365760791","full_name":"Justice-love/go-aspect","owner":"Justice-love","description":"golang aspect tool","archived":false,"fork":false,"pushed_at":"2021-10-12T02:39:23.000Z","size":1539,"stargazers_count":26,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-07T21:42:25.559Z","etag":null,"topics":["aspect"],"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/Justice-love.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":"2021-05-09T13:34:39.000Z","updated_at":"2023-04-05T06:42:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d1ca7b6-b282-4ec2-b979-26596927fda4","html_url":"https://github.com/Justice-love/go-aspect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Justice-love%2Fgo-aspect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Justice-love%2Fgo-aspect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Justice-love%2Fgo-aspect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Justice-love%2Fgo-aspect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Justice-love","download_url":"https://codeload.github.com/Justice-love/go-aspect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248736211,"owners_count":21153551,"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":["aspect"],"created_at":"2024-08-01T20:00:49.858Z","updated_at":"2025-04-13T15:33:17.350Z","avatar_url":"https://github.com/Justice-love.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## 简介\n\ngo-aspect是一个为golang提供切面编程可能性的工具，可以使用该工具，替换原有的go build来进行编译，将预先配置好的切面编织到目标代码中\n\n## 效果图\n\n![效果图](https://user-images.githubusercontent.com/3375778/119075371-3d4cd800-ba23-11eb-87cc-93ee96dd5551.png)\n![效果图](https://user-images.githubusercontent.com/3375778/119075404-48076d00-ba23-11eb-93a6-d6616da8cef8.png)\n\n\n\n## 安装方式\n\n### 源码安装\n\n1. 下载源码到本地\n2. 切换到源码目录，运行 make install\n\n## 使用简介\n1. 目前仅支持mod模式的工程\n2. 编织是基于目标代码下以及依赖包中的`aspect.point`文件进行，文件样例如下：\n```bigquery\n\nimport \"context\"\nimport \"fmt\"\nimport \"time\"\n\npoint after(test.*X.Inject(c Context)) {\n\tfmt.Println(\"456\")\n\tfmt.Println(\"789\")\n}\n\npoint before(test.Do(c Context)) {\n\t{{c}} = context.WithValue({{c}}, \"date\", time.Now())\n}\n\n```\n\n文件分成两部分，\n1. 添加import依赖\n2. 对应的point切入点信息，下文是对其的解释\n\n```bigquery\n//固定值point    织入方式  对应的函数  方法参数\npoint           before(test.Do(c Context)) {\n//  织入的代码\n    {{c}} = context.WithValue({{c}}, \"date\", time.Now())\n}\n```\n\n1. 织入方式：目前支持 before，after， around三种方式\n2. 对应函数：包名.[方法的接收者].函数名，方法接收者如果没有可以不填\n    * 如果织入的代码中使用到了接收者，接收者的参数为去掉*前缀的变量，如test.*X.Inject中，使用X，并且需要使用{{X}}占位符表明接收者\n3. 方法参数：需要按照代织入的方法参数顺序进行编写，现支持的参数类型，struct（使用对应的类型，不需要带前缀），map，slice，array，func，interface，chan（channel）。\n    * `point after(test.*X.Inject(c Context, m map, s slice, i interface, f func)) {`\n    * 如果织入的代码中有使用到对应的参数，请使用{{c}}这样的占位符表明\n\n### 编译\n\n1. xgc build：编译代码，和go build一样，直接执行编译后的文件即可\n2. xgc debug：生成织入后的代码，用以问题排查，代码存放在$USER_HOME/.xgc下\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJustice-love%2Fgo-aspect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJustice-love%2Fgo-aspect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJustice-love%2Fgo-aspect/lists"}