Disgo uses generators to easily update and maintain over 10,000 lines of code.
Use go build -o gen
from the ./_gen
directory to build the executable file for the generator. This may require you to set the GOWORK
environment variable to off
.
The following dependencies are used to download and unzip the latest version of dasgo
to ./gen/input/dasgo-10
(git-ignored).
The following dependencies are used during code generation.
Disgo sources Discord API objects from dasgo. All updates to Discord API Structs should be made in that repository.
Step | Description |
---|---|
download | Download an updated version of dasgo for modification (-d ). |
endpoints | dasgo endpoints (which must be removed) are converted into disgo endpoint functions. |
xstruct | dasgo structs are extracted into one file. Uses option to include var and const . |
typefix | Snowflake , Nonce , and Value fields are converted to string . |
Disgo generates code for features using copygen. This requires corresponding setup.go
files to be updated. Use the diff
from Git to update those files accordingly.
Step | Description |
---|---|
send.go |
Uses copygen to generate request Send() functions. |
handle.go |
Uses copygen to generate request event handling functionality. |
sendevent.go |
Uses copygen to generate gateway SendEvent() functions. |
sendevent.go (shard) |
Uses copygen to generate gateway SendEvents() functions. |
Clean | Cleans the generated code. |
A bundler is used to package the API Wrapper into the disgo
package (disgo.go
). Use go build
from the ./_gen/bundle
directory to build the executable file for the bundler. This may require you to set the GOWORK
environment variable to off
.
- bundle:
go install golang.org/x/tools/cmd/bundle@latest
- fieldalignment:
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
The fieldalignment
tool is prone to removing comments from fieldaligned fields. Use the following steps to add removed comments from fields back.
- Create a file in
_gen/bundle/tools/replaced
. - Add the fieldaligned type (with removed comments) to the file.
- Add a boundary (
---
) on its own line. - Add the fieldaligned type (with comments added) to the file.
Files must end with a single trailing newline.
Run bundle
again to replace the fieldaligned type (without comments) in the Replace
step.