golang aspect tool

简介

go-aspect是一个为golang提供切面编程可能性的工具,可以使用该工具,替换原有的go build来进行编译,将预先配置好的切面编织到目标代码中

效果图

效果图 效果图

安装方式

源码安装

  1. 下载源码到本地
  2. 切换到源码目录,运行 make install

使用简介

  1. 目前仅支持mod模式的工程
  2. 编织是基于目标代码下以及依赖包中的aspect.point文件进行,文件样例如下:

import "context"
import "fmt"
import "time"

point after(test.*X.Inject(c Context)) {
	fmt.Println("456")
	fmt.Println("789")
}

point before(test.Do(c Context)) {
	{{c}} = context.WithValue({{c}}, "date", time.Now())
}

文件分成两部分,

  1. 添加import依赖
  2. 对应的point切入点信息,下文是对其的解释
//固定值point    织入方式  对应的函数  方法参数
point           before(test.Do(c Context)) {
//  织入的代码
    {{c}} = context.WithValue({{c}}, "date", time.Now())
}
  1. 织入方式:目前支持 before,after, defer三种方式
  2. 对应函数:包名.[方法的接收者].函数名,方法接收者如果没有可以不填
    • 如果织入的代码中使用到了接收者,接收者的参数为去掉*前缀的变量,如test.*X.Inject中,使用X,并且需要使用{{X}}占位符表明接收者
  3. 方法参数:需要按照代织入的方法参数顺序进行编写,现支持的参数类型,struct(使用对应的类型,不需要带前缀),map,slice,array,func,interface。
    • point after(test.*X.Inject(c Context, m map, s slice, i interface, f func)) {
    • 如果织入的代码中有使用到对应的参数,请使用{{c}}这样的占位符表明

编译

  1. xgc build:编译代码,和go build一样,直接执行编译后的文件即可
  2. xgc debug:生成织入后的代码,用以问题排查,代码存放在$USER_HOME/.xgc下
Similar Resources

Open-in-linear - A tool provides a shortcut to opening a linear issue in the desktop app or browser

This tool provides a shortcut to opening a linear issue in the desktop app or browser.

Jan 25, 2022

OpenStreetMap PBF golang parser

pbf OpenStreetMap PBF golang encoder/decoder A golang based OpenStreetMap PBF encoder/decoder with a handy command line utility, pbf. pbf Command Line

Oct 23, 2022

golang OpenGL helper functions

glh: golang OpenGL helpers This package contains a number of functions useful for applications using OpenGL. Code Reference Features Textures and Text

Apr 8, 2022

A library for playing with colors in go (golang).

A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Dec 30, 2022

gumble is a Mumble client implementation in Go (golang)

gumble gumble is a Mumble client implementation in Go Sub-projects gumble (docs) Client library gumbleopenal (docs) OpenAL audio system for gumble gum

Jan 5, 2023

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022

Pure golang image resizing

Pure golang image resizing

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Jan 9, 2023

:triangular_ruler: Create beautiful generative image patterns from a string in golang.

:triangular_ruler: Create beautiful generative image patterns from a string in golang.

geopattern Create beautiful generative image patterns from a string in golang. Go port of Jason Long's awesome GeoPattern library. Read geopattern's d

Dec 29, 2022

Pure Golang Library that allows simple LSB steganography on images

Pure Golang Library that allows simple LSB steganography on images

Steganography Lib Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decodi

Dec 22, 2022
Related tags
Faster than the fastest in the world pixel-by-pixel image difference tool.

imgdiff Faster than the fastest in the world pixel-by-pixel image difference tool. Why? imgdiff isn't as fast as a tool like this should be and I'm no

Dec 21, 2022
A cross-platform tool to convert images into ascii art and print them on the console
A cross-platform tool to convert images into ascii art and print them on the console

A cross-platform tool to convert images into ascii art and print them on the console

Dec 30, 2022
An extensive, fast, and accurate command-line image dithering tool.
An extensive, fast, and accurate command-line image dithering tool.

didder is an extensive, fast, and accurate command-line image dithering tool. It is designed to work well for both power users as well as pipeline scripting. It is backed by my dithering library, and is unique in its correctness and variety of dithering algorithms.

Dec 31, 2022
A lightweight and easy to use tool for deflickering timelapse image sequences.
A lightweight and easy to use tool for deflickering timelapse image sequences.

Simple Deflicker A minimalist, lightning-fast and easy to use tool for deflickering image sequences such as timelapses. It's still in its early stages

Aug 12, 2022
a tool to output images as RGB ANSI graphics on the terminal
a tool to output images as RGB ANSI graphics on the terminal

imgcat Tool to output images in the terminal. Built with bubbletea install homebrew brew install trashhalo/homebrew-brews/imgcat prebuilt packages Pr

Dec 28, 2022
Tool to scan a container image's rootfs

image-rootfs-scanner A tool to pull and scan the rootfs of any container image for different binaries. It started out as a means of finding "restricte

Mar 30, 2022
An easy-to-use OCR and Japanese to English translation tool
An easy-to-use OCR and Japanese to English translation tool

Manga Translator An easy-to-use application for translating text in images from Japanese to English. The GUI was created using Gio. Gio supports a var

Dec 28, 2022
🪄 An online tool for making notion-style avatars.
🪄 An online tool for making notion-style avatars.

Notion Avatar Maker An online tool for making notion-style avatars

Jan 3, 2023
JPEG-MPO Decoder / Converter Library and CLI Tool

MPO Decoder Library Simple Go JPEG MPO (Multi Picture Object) Decoder - Library and CLI Tool The library and CLI tool contain the ability to convert M

Sep 26, 2022
Simple tool for changing graphics in dbd

Config changer for Dead By Deaylight For now only for epic store version And if only installed under C:\ further updates will include support for vers

May 3, 2022