Skip to content

Instantly share code, notes, and snippets.

-- db/migrations/${timestamp}_create_user.down.sql
DROP TABLE public.users
-- db/migrations/${timestamp}_create_user.up.sql
CREATE TABLE IF NOT EXISTS public.users
(
id SERIAL PRIMARY KEY,
username VARCHAR(100) NOT NULL UNIQUE
);
// cmd/api/main.go
package main
import (
"github.com/boilerplate/cmd/api/router"
"github.com/boilerplate/pkg/application"
"github.com/boilerplate/pkg/exithandler"
"github.com/boilerplate/pkg/logger"
"github.com/boilerplate/pkg/server"
// cmd/api/handlers/getuser/getuser.go
package getuser
import (
"fmt"
"net/http"
"github.com/boilerplate/pkg/application"
"github.com/julienschmidt/httprouter"
// cmd/api/router/router.go
package router
import (
"github.com/boilerplate/cmd/api/handlers/getuser"
"github.com/boilerplate/pkg/application"
"github.com/julienschmidt/httprouter"
)
// pkg/server/server.go
package server
import (
"errors"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
version: "3.7"
volumes:
boilerplatevolume:
name: boilerplate-volume
networks:
boilerplatenetwork:
name: boilerplate-network
# Start from golang v1.13.4 base image to have access to go modules
FROM golang:1.13.4
# create a working directory
WORKDIR /app
# Fetch dependencies on separate layer as they are less likely to
# change on every build and will therefore be cached for speeding
# up the next build
COPY ./go.mod ./go.sum ./
// cmd/api/main.go
package main
import (
"log"
"github.com/boilerplate/pkg/application"
"github.com/boilerplate/pkg/exithandler"
"github.com/joho/godotenv"
#!/bin/bash
set -e
GO111MODULE=off go get github.com/githubnemo/CompileDaemon
CompileDaemon --build="go build -o main cmd/api/main.go" --command=./main