Screenshots • Installation • Command-line completion • Man documentation • FAQ • Usage
CI Status • Contributing • Thanks • License
𝑎𝑙𝑖𝑔𝑜 is a utility for checking and viewing Golang struct alignment info.
Struct alignment is the extra space added between fields in a struct to align them in memory according to the CPU's word size.
By understanding and managing struct padding (e.g., reordering fields), you can improve program performance, reduce memory usage, and ensure data integrity.
This tool aims to provide a visual way, but also a GitHub Action to report possible improvements in your code.
You can refer @codingwithkushal's Go struct alignment issues article, if you want to understand further.
To build the aligo from scratch, make sure you have a working Go 1.22+ workspace (instructions), then:
go install github.com/essentialkaos/aligo/v2@latest
For using aligo with GitHub Actions use this workflow file or add job Aligo
to your workflow:
name: Aligo
on:
push:
branches: [master, develop]
pull_request:
branches: [master]
jobs:
Aligo:
name: Aligo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.22.x'
- name: Check Golang sources with Aligo
uses: essentialkaos/aligo-action@v2
with:
files: ./...
You can generate completion for bash
, zsh
or fish
shell.
Bash:
sudo aligo --completion=bash 1> /etc/bash_completion.d/aligo
ZSH:
sudo aligo --completion=zsh 1> /usr/share/zsh/site-functions/aligo
Fish:
sudo aligo --completion=fish 1> /usr/share/fish/vendor_completions.d/aligo.fish
You can generate man page for aligo using next command:
aligo --generate-man | sudo gzip > /usr/share/man/man1/aligo.1.gz
Q: I think my struct is well aligned. How can I disable check for it?
A: You could add a comment with text aligo:ignore
for this struct, and aligo will ignore all problems with it. Example:
// This is my supa-dupa struct
// aligo:ignore
type MyStruct struct {
A bool
B int
}
Branch | Status |
---|---|
master |
|
develop |
Before contributing to this project please read our Contributing Guidelines.
We would like to thank: