All Projects → AkihiroSuda → aspectgo

AkihiroSuda / aspectgo

Licence: BSD-3-Clause license
Aspect-Oriented Programming framework for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to aspectgo

KYHooker
A library for complex aspect oriented programming
Stars: ✭ 38 (-38.71%)
Mutual labels:  hook, aspect-oriented-programming
Stinger
Stinger is a high-efficiency library with great compatibility, for aop in Objective-C, using libffi instead of Objective-C message forwarding. It is 20+ times faster than the Aspects, from message-sending to Aspect-oriented code ends.
Stars: ✭ 845 (+1262.9%)
Mutual labels:  hook, aop
Beike AspectD
Flutter AOP framework.(Flutter面向切面库, 最新适配Flutter v2.5.3, null-safety)
Stars: ✭ 39 (-37.1%)
Mutual labels:  hook, aop
AspecTS
An aspect-oriented programming library implemented in TypeScript
Stars: ✭ 21 (-66.13%)
Mutual labels:  aop, aspect-oriented-programming
Easyrouter
A simple android framework used to route activity or action with url.
Stars: ✭ 164 (+164.52%)
Mutual labels:  hook, aop
goaop-laravel-bridge
Integration bridge for Go! AOP framework and Laravel
Stars: ✭ 91 (+46.77%)
Mutual labels:  aop, aspect-oriented-programming
Epic
Dynamic java method AOP hook for Android(continution of Dexposed on ART), Supporting 5.0~11
Stars: ✭ 3,434 (+5438.71%)
Mutual labels:  hook, aop
Reshade
A generic post-processing injector for games and video software.
Stars: ✭ 2,285 (+3585.48%)
Mutual labels:  hook, injector
Virtualxposed
A simple app to use Xposed without root, unlock the bootloader or modify system image, etc.
Stars: ✭ 12,648 (+20300%)
Mutual labels:  hook, aop
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (+50%)
Mutual labels:  hook, aop
Mimick.Fody
An integrated framework for dependency injection and aspect-oriented processing.
Stars: ✭ 15 (-75.81%)
Mutual labels:  aop, aspect-oriented-programming
NCop
Composite-aspect oriented framework for .NET
Stars: ✭ 30 (-51.61%)
Mutual labels:  aop, aspect-oriented-programming
CNeptune
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
Stars: ✭ 30 (-51.61%)
Mutual labels:  aop, aspect-oriented-programming
Aspect4Delphi
Concepts of aspect-oriented programming (AOP) in Delphi.
Stars: ✭ 28 (-54.84%)
Mutual labels:  aop, aspect-oriented-programming
Sandhook
Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat
Stars: ✭ 1,172 (+1790.32%)
Mutual labels:  hook, aop
Pine
Dynamic java method hook framework on ART.
Stars: ✭ 171 (+175.81%)
Mutual labels:  hook, aop
Decor.NET
A simple way to decorate a class with additional functionality using attributes.
Stars: ✭ 29 (-53.23%)
Mutual labels:  aop, aspect-oriented-programming
dodrugs
A macro-powered dependency injector for Haxe
Stars: ✭ 29 (-53.23%)
Mutual labels:  injector
use-async-memo
React hook for generating async memoized data.
Stars: ✭ 130 (+109.68%)
Mutual labels:  hook
RedditVanced
Reddit Android app mod inspired by Aliucord
Stars: ✭ 41 (-33.87%)
Mutual labels:  hook

AspectGo: AOP Framework for Go

Join the chat at https://gitter.im/AkihiroSuda/aspectgo Build Status Go Report Card

AspectGo is an AOP framework for Go. You can write an aspect in a simple Go-compatible grammar.

I'm hoping to propose merging AspectGo to the upstream of golang.org/x/exp if possible, but no concret plan yet.

Recipe:

  • Logging
  • Assertion
  • Fault injection
  • Mocking
  • Coverage-guided genetic fuzzing (as in AFL)
  • Fuzzed(randomized) scheduling

The interface is not fixed yet. Your suggestion and PR are welcome.

Install

$ go install github.com/AkihiroSuda/aspectgo/cmd/aspectgo

Example

$ go build github.com/AkihiroSuda/aspectgo/example/hello && ./hello
hello
$ aspectgo \
  -w /tmp/wovengopath \                         # output gopath
  -t github.com/AkihiroSuda/aspectgo/example/hello \  # target package
  example/hello/main_aspect.go                  # aspect file
$ GOPATH=/tmp/wovengopath go build github.com/AkihiroSuda/aspectgo/example/hello && ./hello
BEFORE hello
hello
AFTER hello

The aspect is located on example/hello/main_aspect.go:

package main

import (
	"fmt"
	"regexp"

	asp "github.com/AkihiroSuda/aspectgo/aspect"
)

// ExampleAspect implements interface asp.Aspect
type ExampleAspect struct {
}

// Executed on compilation-time
func (a *ExampleAspect) Pointcut() asp.Pointcut {
	pkg := regexp.QuoteMeta("github.com/AkihiroSuda/aspectgo/example/hello")
	s := pkg + ".*"
	return asp.NewCallPointcutFromRegexp(s)
}

// Executed ONLY on runtime
func (a *ExampleAspect) Advice(ctx asp.Context) []interface{} {
	args := ctx.Args()
	fmt.Println("BEFORE hello")
	res := ctx.Call(args)
	fmt.Println("AFTER hello")
	return res
}

The target is example/hello/main.go:

package main

import (
	"fmt"
)

func sayHello(s string) {
	fmt.Println("hello " + s)
}

func main() {
	sayHello("world")
}

You can also execute other examples as follows:

$ go test -v github.com/AkihiroSuda/aspectgo/example

If the output is hard to read, please add the -parallel 1 flag to go test.

Hint

  • Clean /tmp/wovengopath before running aspectgo every time.
  • Clean GOPATH before running aspectgo for faster compilation.

Current Limitation

  • Only single aspect file is supported (But you can define multiple aspects in a single file)
  • Only regexp for function name (excluding main and init) and method name can be a pointcut
  • Only "call" pointcut is supported. No support for "execution" pointcut yet:
    • 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.
    • 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)
  • Only "around" advice is supported. No support for "before" and "after" pointcut.
  • If an object hits multiple pointcuts, only the last one is effective.

Related Work

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].