Code Monkey home page Code Monkey logo

allaboutapps / go-starter Goto Github PK

View Code? Open in Web Editor NEW
440.0 12.0 58.0 6.45 MB

An opinionated production-ready SQL-/Swagger-first RESTful JSON API written in Go, highly integrated with VSCode DevContainers by allaboutapps.

Home Page: https://github.com/allaboutapps/go-starter/wiki/FAQ

License: MIT License

Dockerfile 2.22% Makefile 4.23% Go 91.36% Shell 0.55% PLpgSQL 0.99% JavaScript 0.65%
golang-development vscode-devcontainers golang go server oauth2 vscode docker pgformatter swagger postgresql sqlboiler allaboutapps sql id-allaboutapps-backend

go-starter's Introduction

go-starter

go-starter is an opinionated production-ready RESTful JSON backend template written in Go, highly integrated with VSCode DevContainers by allaboutapps.

License: MIT Build and Test codecov Go Report Card Swagger Validator GitHub contributors Mentioned in Awesome Go

go starter overview

Demo: https://go-starter.allaboutapps.at FAQ: https://github.com/allaboutapps/go-starter/wiki/FAQ

Table of Contents

Features

  • Full local golang service development environment using Docker Compose and VSCode devcontainers that just works with Linux, MacOS and Windows.
  • Adheres to the project layout defined in golang-standard/project-layout.
  • Provides database migration (sql-migrate) and models generation (SQLBoiler) workflows for PostgreSQL databases.
  • Integrates IntegreSQL for fast, concurrent and isolated integration testing with real PostgreSQL databases.
  • Auto-installs our recommended VSCode extensions for golang development.
  • Integrates go-swagger for compile-time generation of swagger.yml, structs and request/response validation functions.
  • Integrates MailHog for easy SMTP-based email testing.
  • Integrates SwaggerUI for live-previewing your Swagger v2 schema.
  • Integrates pgFormatter and vscode-pgFormatter for SQL formatting.
  • Comes with fully implemented auth package, an OAuth2 RESTful JSON API ready to be extended according to your requirements.
  • Implements OAuth 2.0 Bearer Tokens and password authentication using argon2id hashes.
  • Comes with a tested mock and FCM provider for sending push notifications and storing push tokens.
  • CLI layer provided by spf13/cobra. It's exceptionally easy to add additional sub-commands via cobra-cli.
  • Comes with an initial PostgreSQL database structure (see /migrations), covering:
    • auth tokens (access-, refresh-, password-reset-tokens),
    • a generic auth-related user model
    • an app-specific bare-bones app_user_profile model,
    • push notification tokens and
    • a health check sequence (for performing writeable checks).
  • API endpoints and CLI for liveness (/-/healthy) and readiness (/-/ready) probes
  • Parallel jobs optimized Makefile and various convenience scripts (see all targets and its description via make help). A full rebuild only takes seconds.
  • Multi-staged Dockerfile (development -> builder -> app).

Usage

Please find more detailed information regarding the history, usage and other whys? of this project in our FAQ.

Demo

A demo go-starter service is deployed at https://go-starter.allaboutapps.at for you to play around with.

Please visit our FAQ to find out more about the limitations of this demo environment.

Requirements

Requires the following local setup for development:

This project makes use of the Remote - Containers extension provided by Visual Studio Code. A local installation of the Go tool-chain is no longer required when using this setup.

Please refer to the official installation guide how this works for your host OS and head to our FAQ: How does our VSCode setup work? if you encounter issues.

Quickstart

Create a new git repository through the GitHub template repository feature (use this template). You will then start with a single initial commit in your own repository.

# Clone your new repository, cd into it, then easily start the docker-compose dev environment through our helper
./docker-helper.sh --up

You should be inside the 'service' docker container with a bash shell.

development@94242c61cf2b:/app$ # inside your container...

# Shortcut for make init, make build, make info and make test
make all

# Print all available make targets
make help

Merge with the go-starter template repository to get future updates

These steps are not necessary if you have a "real" fork.

If your new project is generated from a template project (you have a single commit), you want to run the following command immediately and before applying any changes. Otherwise you won't be able to easily merge upstream go-starter changes into your own repository (see GitHub Template Repositories, Refusing to merge unrelated histories and FAQ: I want to compare or update my project/fork to the latest go-starter master).

make git-merge-go-starter
# Attempting to execute 'git merge --no-commit --no-ff go-starter/master' into your current HEAD.
# Are you sure? [y/N]y
# git merge --no-commit --no-ff --allow-unrelated-histories go-starter/master

git commit -m "Initial merge of unrelated go-starter template history"

Set project module name for your new project

To replace all occurrences of allaboutapps.dev/aw/go-stater (our internal module name of this project) with your desired projects' module name, do the following:

development@94242c61cf2b:/app$ # inside your container...

# Set a new go project module name.
make set-module-name
# allaboutapps.dev/<GIT_PROJECT>/<GIT_REPO> (internal only)
# github.com/<USER>/<PROJECT>
# e.g. github.com/majodev/my-service

The above command writes your new go module name to tmp/.modulename, go.mod. It actually sets it everywhere in **/* - thus this step is typically only required once. If you need to merge changes from the upstream go-starter later, we may want to run make force-module-name to set your own go module name everywhere again (especially relevant for new files / import paths). See our FAQ for more information about this update flow.

Optionally you may want to move the original README.md and LICENSE away:

development@94242c61cf2b:/app$ # inside your container...

# Optionally you may want to move our LICENSE and README.md away.
mv README.md README-go-starter.md
mv LICENSE LICENSE-go-starter

# Optionally create a new README.md for your project.
make get-module-name > README.md

Visual Studio Code

If you are new to VSCode Remote - Containers feature, see our FAQ: How does our VSCode setup work?.

Run CMD+SHIFT+P Go: Install/Update Tools after attaching to the container with VSCode to auto-install all golang related vscode extensions.

Building and testing

Other useful commands while developing your service:

development@94242c61cf2b:/app$ # inside your container...

# Print all available make targets
make help

# Shortcut for make init, make build, make info and make test
make all

# Init install/cache dependencies and install tools to bin
make init

# Rebuild only after changes to files (generate, format, build, lint)
make

# Execute all tests
make test

Running

To run the service locally you may:

development@94242c61cf2b:/app$ # inside your development container...

# First ensure you have a fresh `app` executable available
make build

# Check if all requirements for becoming are met (db is available, mnt path is writeable)
app probe readiness -v

# Migrate up the database
app db migrate

# Seed the database (if you have any fixtures defined in `/internal/data/fixtures.go`)
app db seed

# Start the locally-built server
app server

# Now available at http://127.0.0.1:8080

# You may also run all the above commands in a single command
app server --probe --migrate --seed # or `app server -pms`

Uninstall

Simply run ./docker-helper --destroy in your working directory (on your host machine) to wipe all docker related traces of this project (and its volumes!).

Additional resources

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Current maintainers

Previous maintainers

License

MIT

go-starter's People

Contributors

amather avatar anjankow avatar danut007ro avatar dependabot[bot] avatar eklatzer avatar eldelto avatar farkmi avatar liggitt avatar majodev avatar mwieser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-starter's Issues

Problem with devcontainer.json

devcontainer.json does not build in JetBrains IDE 2024.1 and VSCode.

JetBrains IDE Welcome screen -> DevContainers -> New DevContainer (from VCS Project, Docker must be installed.) Insert the git@ link of the repository with devcontainer.json. -> "Build container and Continue"

image image

Bug mit M2 Prozessor

Beim Versuch den Package zu installieren und auf dem Macbook mit M2 Prozessot laufen lassen, Installierung von Golangci-lint schlägt fehl. Das passiert, weil Packages mit curl heruntergeladen werden und es kann nicht richtig erkennen, welche zu laden.

# go linting: (this package should NOT be installed via go get)
# https://github.com/golangci/golangci-lint#binary
# https://github.com/golangci/golangci-lint/releases
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
    | sh -s -- -b $(go env GOPATH)/bin v1.45.2

Momentan in Docker File sieht es so aus.

Es ist möglich dieses Problem zu beheben, wenn man stattdessen doch mit Go Install Golangci-lint installiert.
RUN go install github.com/golangci/golangci-lint/cmd/[email protected]
Dann wird Go richtige Version für richtige Prozessorarchitektur installieren.

localhost:8080 -> localhost didn’t send any data.

I was running successfully from docker compose, and swagger ui (localhost:8081) could be opened from browser, but there is error when access go-service at localhost:8080

these are error captures.

image

image

could you help me ?

Bug in swagger generator

Hi team,

I'm not sure if this is a bug or not, but why is this line necessary in the makefile swagger-generate?

rsync -au --size-only --ignore-times --delete tmp/testdata/types/ internal/types/

this code seems to replace code in internal/types directory with code in tmp/testdata/types/. This causes build errors, for example when running make all twice in a row.

It's not clear to me why this code is necessary. Can someone comment on this please.
Thanks

Failed to fetch all endpoints.

After successfully running the project I'm getting the message:

In swagger:
Failed to fetch. Possible Reasons: CORSNetwork FailureURL scheme must be "http" or "https" for CORS request.

and in a web browser:

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

make swagger error

When I use make swagger to generate swagger.yml. The following error occurs

development@8a8695961136:/app$ make swagger
make swagger-concat
make[1]: *** [Makefile:266: swagger-concat] Error 3
make: *** [Makefile:239: swagger] Error 2

But when I run every commad in swagger-concat alone, every command is successful
Why?

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.