Go API Starter

This library is a starter for an API implemented in GoLang. It comes with user login functionality, logging capablities, and environment-based configurations. If login functionality isn't required it can easily be used as an example and replaced with appropriate endpoint logic using the steps outlined below. Stack includes grpc, buf/connect-go, MySQL, and GORM. There is also an accompanying front-end starter built using Qwik to demo a typescript/client implementation of connect-go: qwik-client-starter (WIP)

Run As-Is 🍶

1. Install Go and Dependencies

  • Install Go
  • Clone this repo, cd into directory and run
     $ go get github.com/mvpoyatt/go-api/api
     $ go get github.com/mvpoyatt/go-api/configs
     $ go get github.com/mvpoyatt/go-api/database
     $ go mod tidy

2. Download MySQL and MySQL Workbench

  • MySQL - Replace db:password in /configs/development.yaml with password you enter here
  • MySQL Workbench - Create new schema named testdb or replace db:dbname in /configs/development.yaml with name of new schema

3. Start Server

  • In root directory of project run
     $ go run main.go

To Work with Buf 🌋

  1. Install buf tools
  2. Install connect tools
  3. Remove existing code and re-generate
    $ rm -rf gen/
    $ buf generate
    • This generates code in gen/ folder. Delete and re-run after changing .proto file.

Creating New Endpoints 🔌

  1. Add new API folders to buf.work.yaml
  2. Update buf.gen.yaml for new:
    • Code generating plugins
    • External packages (exlude default go_option prefixes)
  3. In home directory of project run
    $ rm -rf gen  # reset existing generated code
    $ buf lint
    $ buf build
    $ buf generate

License

MIT