{"id":16542532,"url":"https://github.com/akihirosuda/aspectgo","last_synced_at":"2025-03-21T10:31:10.874Z","repository":{"id":93537763,"uuid":"61690443","full_name":"AkihiroSuda/aspectgo","owner":"AkihiroSuda","description":"Aspect-Oriented Programming framework for Go","archived":false,"fork":false,"pushed_at":"2016-08-02T01:34:28.000Z","size":43,"stargazers_count":70,"open_issues_count":0,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-18T07:35:08.042Z","etag":null,"topics":["aop","aspect-oriented-programming","golang","hook","injector"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AkihiroSuda.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-06-22T05:06:00.000Z","updated_at":"2024-05-01T13:38:21.000Z","dependencies_parsed_at":"2023-03-15T21:00:24.896Z","dependency_job_id":null,"html_url":"https://github.com/AkihiroSuda/aspectgo","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/AkihiroSuda%2Faspectgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkihiroSuda%2Faspectgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkihiroSuda%2Faspectgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AkihiroSuda%2Faspectgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AkihiroSuda","download_url":"https://codeload.github.com/AkihiroSuda/aspectgo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221814032,"owners_count":16884963,"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":["aop","aspect-oriented-programming","golang","hook","injector"],"created_at":"2024-10-11T18:57:50.374Z","updated_at":"2024-10-28T09:49:23.657Z","avatar_url":"https://github.com/AkihiroSuda.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AspectGo: AOP Framework for Go\n\n[![Join the chat at https://gitter.im/AkihiroSuda/aspectgo](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/AkihiroSuda/aspectgo?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://travis-ci.org/AkihiroSuda/aspectgo.svg?branch=master)](https://travis-ci.org/AkihiroSuda/aspectgo)\n[![Go Report Card](https://goreportcard.com/badge/github.com/AkihiroSuda/aspectgo)](https://goreportcard.com/report/github.com/AkihiroSuda/aspectgo)\n\nAspectGo is an AOP framework for Go.\nYou can write an aspect in a simple Go-compatible grammar.\n\nI'm hoping to propose merging AspectGo to the upstream of [`golang.org/x/exp`](https://godoc.org/golang.org/x/exp) if possible, but no concret plan yet.\n\nRecipe:\n\n * Logging\n * Assertion\n * Fault injection\n * Mocking\n * Coverage-guided genetic fuzzing (as in [AFL](http://lcamtuf.coredump.cx/afl/technical_details.txt))\n * Fuzzed(randomized) scheduling\n\nThe interface is not fixed yet.\nYour suggestion and PR are welcome.\n\n## Install\n\n    $ go install github.com/AkihiroSuda/aspectgo/cmd/aspectgo\n\n## Example\n\n    $ go build github.com/AkihiroSuda/aspectgo/example/hello \u0026\u0026 ./hello\n    hello\n    $ aspectgo \\\n      -w /tmp/wovengopath \\                         # output gopath\n      -t github.com/AkihiroSuda/aspectgo/example/hello \\  # target package\n      example/hello/main_aspect.go                  # aspect file\n    $ GOPATH=/tmp/wovengopath go build github.com/AkihiroSuda/aspectgo/example/hello \u0026\u0026 ./hello\n    BEFORE hello\n    hello\n    AFTER hello\n\nThe aspect is located on [example/hello/main_aspect.go](example/hello/main_aspect.go):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\n\tasp \"github.com/AkihiroSuda/aspectgo/aspect\"\n)\n\n// ExampleAspect implements interface asp.Aspect\ntype ExampleAspect struct {\n}\n\n// Executed on compilation-time\nfunc (a *ExampleAspect) Pointcut() asp.Pointcut {\n\tpkg := regexp.QuoteMeta(\"github.com/AkihiroSuda/aspectgo/example/hello\")\n\ts := pkg + \".*\"\n\treturn asp.NewCallPointcutFromRegexp(s)\n}\n\n// Executed ONLY on runtime\nfunc (a *ExampleAspect) Advice(ctx asp.Context) []interface{} {\n\targs := ctx.Args()\n\tfmt.Println(\"BEFORE hello\")\n\tres := ctx.Call(args)\n\tfmt.Println(\"AFTER hello\")\n\treturn res\n}\n```\n\n\nThe target is [example/hello/main.go](example/hello/main.go):\n```go\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc sayHello(s string) {\n\tfmt.Println(\"hello \" + s)\n}\n\nfunc main() {\n\tsayHello(\"world\")\n}\n```\n\n\nYou can also execute other examples as follows:\n\n    $ go test -v github.com/AkihiroSuda/aspectgo/example\n\nIf the output is hard to read, please add the `-parallel 1` flag to `go test`.\n\n## Hint\n\n * Clean `/tmp/wovengopath` before running `aspectgo` every time.\n * Clean GOPATH before running `aspectgo` for faster compilation.\n\n## Current Limitation\n\n * Only single aspect file is supported (But you can define multiple aspects in a single file)\n * Only regexp for function name (excluding `main` and `init`) and method name can be a pointcut\n * Only \"call\" pointcut is supported. No support for \"execution\" pointcut yet:\n   * Suppose that `*S`, `*T` implements `I`, and there is a call to `I.Foo()` in the target package. You can make a pointcut for `I.Foo()`, but you can't make a pointcut for `*S` nor `*T`.\n   * Aspect cannot be woven to Go-builtin packages. i.e., You can't hook a call _from_ a Go-builtin pacakge. (But you can hook a call _to_ a Go-builtin package by just making a \"call\" pointcut for it)\n * Only \"around\" advice is supported. No support for \"before\" and \"after\" pointcut.\n * If an object hits multiple pointcuts, only the last one is effective.\n \n## Related Work\n\n * [github.com/deferpanic/goweave](https://github.com/deferpanic/goweave)\n * [github.com/gogap/aop](https://github.com/gogap/aop)\n * [golang.org/x/tools/refactor/eg](https://github.com/golang/tools/blob/master/refactor/eg/eg.go) (Not AOP, but has some similarity)\n * [github.com/coreos/gofail](https://github.com/coreos/gofail) (ditto)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakihirosuda%2Faspectgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakihirosuda%2Faspectgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakihirosuda%2Faspectgo/lists"}