Code Monkey home page Code Monkey logo

golang-starter-rest-api's Introduction

Go Rest API Starter

Structure Folder

	├── application
	│   ├── controller
	│   │   ├── ApiController.go
	│   │   └── UserController.go
	│   ├── lib
	│   │   ├── BaseModel.go
	│   │   ├── Middleware.go
	│   │   ├── Request.go
	│   │   └── Response.go
	│   ├── middlewares
	│   │   └── Cors.go
	│   ├── router.go
	│   └── server.go
	├── config
	│   └── database.go
	├── main.go
	└── models
		└── User.go

	6 directories, 12 files

Auto Migration Models

//in main.go
func MigrateDatabase() {
	fmt.Println(":: Migration Databases .....")
	db := config.GetDatabaseConnection()
	db.AutoMigrate(&models.User{}) // model users
	b.AutoMigrate(&models.Profile{}) // model profile
	..
	..
	fmt.Println(":: Migration Databases Done")
}

.env

Create .env file example file .env

ENVIRONMENT="development"

API_TITLE="TEST"
API_VERSION="0.0.0"
API_PORT=3000

DB_DIALECT="mysql"
DB_CONNECTION="username:password@tcp(localhost:3306)/databasename?charset=utf8&parseTime=True"

run

[16:21:15-golang-rest-API-rwx-]$ go run main.go 
:: Checking databse connection ..... 
:: Database Connected
:: Migration Databases .....
:: Migration Databases Done
:: APP running on port 3000

Simple CRUD endpoint

1. Create

[POST] localhost:3000/v1/user/

{
	"FirstName" : "rahmat wahyu",
	"LastName" : "Hadi",
	"Email" : "[email protected]"
}

2. GET ALL

[GET] localhost:3000/v1/user/

3. GET BY ID

[GET] localhost:3000/v1/user/1

4. UPDATE BY ID

[PUT] localhost:3000/v1/user/1

5. DELETE BY ID

[DELETE] localhost:3000/v1/user/1

Contact me

Rahmat Wahyu Hadi ; Telegram : @rwahyu

golang-starter-rest-api's People

Contributors

wahyuhadi 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.