Coder Social home page Coder Social logo

wlanboy / goservice Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 113 KB

Golang Rest service based on gorilla, gorm using Spring cloud config and PostgreSql

License: Apache License 2.0

Go 97.13% Dockerfile 2.87%
go golang gorm gorm-orm gorilla-mux pg godotenv cloud-config spring-cloud-config

goservice's Introduction

Go

goservice

Golang Rest service based on gorilla, gorm using Spring cloud config and PostgreSql

using

  • "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"

build

  • go get -d -v
  • go clean
  • go build

build windows

depends on

run

  • go run main.go

debug

  • go get -u github.com/go-delve/delve/cmd/dlv
  • dlv debug ./goservice

dockerize (docker image size is 9.89MB)

  • 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 publish to github registry

  • docker tag goservice:latest docker.pkg.github.com/wlanboy/goservice/goservice:latest
  • docker push docker.pkg.github.com/wlanboy/goservice/goservice:latest

Docker Hub

Docker Registry repro

run docker container

*docker run -d -p 8000:8000 goservice

Kubernets deployment

Prepare

cd ~
git clone https://github.com/wlanboy/goservice.git

check you local kubectl

kubectl cluster-info
kubectl get pods --all-namespaces

deploy service on new namespace

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

check deployment and service

kubectl describe deployments -n go goservice 
kubectl describe services -n gp goservice-service

expose service and get node port

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>

call microservice

create event

get all events

get prometheus metrics

goservice's People

Contributors

dependabot[bot] avatar snyk-bot avatar wlanboy avatar

Watchers

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