Code Monkey home page Code Monkey logo

test_go_restapi's Introduction

This is the test and practice RESTful API

In this version, gateways includes database information.
And this breaks DIP (Dependency Inversion Principal)

Not a perfect Clean Architecture.

Getting Started

for Mac (or Windows installed make)

To Start DB

make up

To Start API Server

make start

for Windows

To start DB

docker-compose up

To start api server

go run .

API Spec

You can see details in /infrastructures/rounter.go and /adapters/gateways/user_gateways.go

End point Method
~/users/all GET
~/users/range?start=[id]&end=[id] GET
~/users?ids[0]=[id]&ids[1]=[id]&.... GET
~/user/:id GET
  • ~/users/all
    To get all users.
  • ~/users/range?start=[id]&end=[id]
    To get users in a certain ids range.
  • ~/users?ids[0]=[id]&ids[1]=[id]&....
    To get users according to ids
    Ex) ~/users?ids[0]=1&ids[1]=3&ids[2]=8
  • ~/user/:id
    To get a user

To add API End Point

  1. Make a go structure in /entities
  2. Make port and interactor in /usecases
  3. Make controllers, gateways and presenters in /adaptors
  4. Make API endpoint in /infrastructures

To add api tables and columns

  1. Run
migrate create -ext sql -dir database/migrations -seq [sql file name]
  1. Edit database/[version]-migrations/[sql_file_name].up.sql and ~.down.sql

  2. Run

${POSTGRESQL_URL} = 'postgres://user:pass@url:port/tablename'

migrate -path database/migrations -database ${POSTGRESQL_URL} up 

When the migration is failed, your schema is recoded as "dirty". Anyway, fix your migration and Run

To change your schema clear.

migrate -path database/migrations -database ${POSTGRESQL_URL} force 1

And downgrade your tables

migrate -path database/migrations -database ${POSTGRESQL_URL} down 1

And upgrade 1

migrate -path database/migrations -database ${POSTGRESQL_URL} up 1

4.Run To get a go structure from database schema.
See /models/~

sqlboiler psql

test_go_restapi's People

Contributors

shunta0213 avatar

Watchers

 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.