Golang Rest service based on gorilla, gorm using Spring cloud config and PostgreSql
- "context"
- "os"
- "os/signal"
- "syscall"
- "fmt"
- "time"
- "net/http"
- "net/http/httputil"
- "log"
- "encoding/json"
- "github.com/gorilla/mux"
- "github.com/gorilla/handlers"
- "github.com/jinzhu/gorm"
- "github.com/jinzhu/gorm/dialects/postgres"
- "github.com/jinzhu/gorm/dialects/sqlite"
- "github.com/satori/go.uuid"
- "github.com/joho/godotenv"
- "github.com/prometheus/client_golang/prometheus/promhttp"
- go get -d -v
- go clean
- go build
- install https://jmeubank.github.io/tdm-gcc/
- go get github.com/mattn/go-sqlite3 in windows shell
- PostgreSQL instance: https://github.com/wlanboy/Dockerfiles/tree/master/Postgres
- go run main.go
- go get -u github.com/go-delve/delve/cmd/dlv
- dlv debug ./goservice
- GOOS=linux GOARCH=386 go build (386 needed for busybox)
- GOOS=linux GOARCH=arm GOARM=6 go build (Raspberry Pi build)
- GOOS=linux GOARCH=arm64 go build (Odroid C2 build)
- docker build -t goservice .
- docker tag goservice:latest docker.pkg.github.com/wlanboy/goservice/goservice:latest
- docker push docker.pkg.github.com/wlanboy/goservice/goservice:latest
*docker run -d -p 8000:8000 goservice
cd ~
git clone https://github.com/wlanboy/goservice.git
kubectl cluster-info
kubectl get pods --all-namespaces
cd ~/goservice
kubectl create namespace go
kubectl apply -f goservice-deployment.yaml
kubectl apply -f goservice-service.yaml
kubectl get pods -n go -o wide
kubectl describe deployments -n go goservice
kubectl describe services -n gp goservice-service
kubectl expose deployment -n go goservice --type=NodePort --name=goservice-serviceexternal --port 8000
kubectl describe services -n go goservice-serviceexternal
Result:
Name: goservice-serviceexternal
Namespace: go
Labels: app=goservice
Annotations: <none>
Selector: app=goservice
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.108.40.139
IPs: 10.108.40.139
Port: <unset> 8000/TCP
TargetPort: 8002/TCP
NodePort: <unset> 30413/TCP <--- THIS IS THE PORT WE NEED
Endpoints: 10.10.0.8:8000
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
- curl -X POST http://127.0.0.1:8000/api/v1/event -H 'Content-Type: application/json' -d '{"name": "test", "type": "info"}'
- curl -X GET http://127.0.0.1:8000/api/v1/event
- curl -X GET http://127.0.0.1:8000/metrics