Giter Club home page Giter Club logo

go-todo-api's Introduction

go-fiber-api

Development

Prerequisites

  • Go

  • Docker (optional) - for running the database

  • Make (optional) - for running the Makefile commands (shortcuts for other commands)

  • Air (optional) - for hot reloading while developing

  • Ginkgo (optional) - for running the tests

Getting started

  1. Clone the repository
git clone
  1. Install dependencies
go mod download
  1. Create a .env file in the root of the project by copying the .env.example file and filling in the correct values
cp .env.example .env
  1. Run the migrations
make migrate-up
  1. Generate the TEMPL files
templ generate
  1. Run the server
make run
# or (if you have Air installed)
air

Knowledge base

TEMPL

TEMPL

JSON parsing with go

Because the BodyParser will default parse null string fields as empty strings, we need a better solution to get actual null values With the omitempty tag, we also won't get the desired result, because it will omit the field if it's null (and then use the default value - empty string)

The solution is to use the packages "gopkg.in/guregu/null.v4/zero" and "gopkg.in/guregu/null.v4/null" And then use the types zero.String and null.String instead of string

Because these will use a struct under the hood, we also want to overwrite the swagger documentation for these fields, so that it will show the correct type in the docs with swaggertype:"string" tag

Migrations

We use Atlas for schema based migrations. Because we use GORM as our ORM, we can use the https://atlasgo.io/guides/orms/gorm package to generate migrations directly from our models. The configuration for this happens in atlas.hcl and loader/atlasGorm.go

We wrap the most common Atlas commands in the Makefile, so that we can easily run them. The commands are:

# Generate a new migration file based on the current models
make migrate-gen name=<migration-name>

# Generate a new empty migration file
make migrate-new name=<migration-name>

# Apply all migrations up to the latest version
make migrate-up

# Reverse all migrations down to the given version (version is the timestamp of the migration file)
make migrate-down version=<version>

go-todo-api's People

Contributors

tkspectro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.