Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

kamaslau/trial-fiber

Repository files navigation

trial-fiber

License: MIT Repository size

Template Fiber framework project for fast prototyping, trial, or micro-service unit usage.

Make sure that you have Golang installed already.

[🇨🇳 Optional] Setup Mirror for Mainland China

You can safely skip this part if not approaching the internet from within mainland China.

go env -w GOPROXY=https://goproxy.io,direct # Official
go env -w GOPROXY=https://goproxy.cn,direct # QiniuCloud/七牛云

go env GOPROXY # Double check

Service Endpoints

RESTful

GraphQL (TODO)

curl -X POST \
http://127.0.0.1:3000/graphql/ \
-H 'Content-Type: application/json' \
-d '{
  "query": "query { posts { id name } }"
}'

Usage

Create a trial-fiber database (you can use another name, just config it in the .env file) in PostgreSQL/MySQL/MariaDB of yours, then follow these steps below.

# Create .env file
cp .env.sample .env # at least specify a database connection info

# Install dependencies
go get ./...

# [Optional] Update dependencies
go get -u ./...
go mod tidy

Run

Without live-reloading

go run ./src/...

With live-reloading (via air-verse/air)

# Install Air
go install github.com/air-verse/air@latest

# Run with
air # Linux/macOS
air -c .air.windows.toml # Windows

For more detailed instructions, e.g. solutions on working cross OS, checkout https://manual.kamaslau.com/golang/tools/air.html.

Compile

Remember to put a .env file in to the same directory with the executable file compiled

go build -o ./dist/main ./src

Deploy (via docker)

docker build . -t trial-fiber:latest

docker network create trial-backend && \
docker stop trial-fiber && \
docker rm trial-fiber && \
docker run --name trial-fiber --network trial-backend -p 3000:3000 -d --restart always --net=host trial-fiber:latest

Make sure that other service components (database, cache, MQ, etc.) are within the same network, e.g.,

docker network connect trial-backend trial-fiber
docker network connect trial-backend database-xxx
docker network connect trial-backend mq-xxx

References/Credits

About

Trial or micro-service unit of Golang Fiber framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages