pegasus-io / lets-go

My path learning Golang
0 stars 0 forks source link

Lets go

My path learning Golang

How to run

export DESIRED_VERSION=0.0.1

git clone git@github.com:pegasus-io/lets-go.git ~/lets-go

cd ~/lets-go

git checkout ${DESIRED_VERSION}
go run main.go
curl -iv http://localhost:10101/api/v1
# # or
curl -iv http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X POST http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X PUT http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X PATCH http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X DELETE http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X OPTIONS http://localhost:10101/api/v1 | tail -n 1 | jq
#
curl -iv -X POST http://localhost:10101/api/v1/user/544543434/comment | tail -n 1 | jq
#
curl -iv -X GET http://localhost:10101/api/v1/user/544543434/comment/45446464634 | tail -n 1 | jq

What I learned about Golang

Setting the env variables, and bootstrap a new golang project

export PATH=$PATH:/usr/local/go/bin

export NAME_OF_MY_GOLANG_PROJECT=pegasus-api
go mod init ${NAME_OF_MY_GOLANG_PROJECT}

Dealing with dependencies

export PATH=$PATH:/usr/local/go/bin
go get -u github.com/gorilla/mux
package somepackage

import (
    "github.com/gorilla/mux"
)

func myAwesomeFunction() {
  r := mux.NewRouter()
}

Next article : Open API and swagger generate the source code / the Open API documentation