Skip to content

Commit

Permalink
go mod add
Browse files Browse the repository at this point in the history
  • Loading branch information
sedflix committed Oct 2, 2020
1 parent 849d574 commit 7db7160
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Dockerfile
draft.toml
charts/
charts
src/credentials.json
40 changes: 39 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,42 @@ src/credentials.json
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# vendor/

# General files for the project
pkg/*
*.pyc
bin/*
.project
/.bin
/_test/secrets/*.json

# OSX leaves these everywhere on SMB shares
._*

# OSX trash
.DS_Store

# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
.idea/
*.iml

# Vscode files
.vscode

# Emacs save files
*~
\#*\#
.\#*

# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist

# Chart dependencies
**/charts/*.tgz

.history
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM golang:latest as builder
LABEL maintainer="Siddharth <[email protected]>"

WORKDIR /app
COPY src/ app/
COPY src/ .
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

Expand All @@ -12,7 +12,12 @@ FROM alpine:latest

RUN apk --no-cache add ca-certificates tzdata
ENV TZ=Asia/Kolkata
ENV GIN_MODE=release

WORKDIR /root/
COPY src/web web

COPY --from=builder /app/main .
EXPOSE 8080

CMD ["./main"]
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
TODO:
- [ ] rearrange folder
- [ ] add ui template
kubectl create secret generic google_creds --from-file=src/credentials.json
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
cloud.google.com/go v0.66.0 // indirect
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/gin-contrib/pprof v1.3.0
github.com/gin-contrib/cache v1.1.0
github.com/gin-gonic/contrib v0.0.0-20200913005814-1c32036e7ea4
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/sessions v1.2.1 // indirect
Expand Down
32 changes: 27 additions & 5 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package main

import (
"fmt"
"github.com/gin-contrib/cache"
"github.com/gin-contrib/cache/persistence"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"time"
)

func ErrorHandle() gin.HandlerFunc {
Expand All @@ -22,6 +26,19 @@ func ErrorHandle() gin.HandlerFunc {
}
}

func health(ctx *gin.Context) {
if mongoClient != nil && config != nil {
ctx.JSON(http.StatusOK,
gin.H{
"health": "ok",
})
}
ctx.JSON(http.StatusBadGateway,
gin.H{
"health": "lol",
})
}

func main() {

//setTimeZone
Expand All @@ -31,19 +48,23 @@ func main() {
}

// mongodb connection
mongoURI := "mongodb://localhost:27017"
mongoURI := "mongodb://mongo:27017"
err = setupMongo(mongoURI)
if err != nil {
return
}

// oauth connection
err = setupOAuthClientCredentials("./credentials.json")
err = setupOAuthClientCredentials("/etc/secret/credentials.json")
if err != nil {
return
}

router := gin.Default()
gin.SetMode(gin.ReleaseMode)

// cache setup
cacheStore := persistence.NewInMemoryStore(time.Minute)

// setup session cookie storage
var store = sessions.NewCookieStore([]byte("secret"))
Expand All @@ -59,14 +80,15 @@ func main() {
router.StaticFile("/favicon.ico", "./web/favicon.ico")
router.LoadHTMLFiles("web/index.html")

router.GET("/", index) // index page
router.GET("/list/json", list) // show information in json
router.GET("/", cache.CachePageWithoutQuery(cacheStore, 5*time.Minute, index)) // index page
router.GET("/list/json", list) // show information in json

router.GET("/login", authoriseUserHandler) // to register
router.GET("/auth", oAuthCallbackHandler) // oauth callback

router.GET("/health", health)
// Add the pprof routes
//pprof.Register(router)

_ = router.Run("127.0.0.1:9090")
_ = router.Run("0.0.0.0:8080")
}

0 comments on commit 7db7160

Please sign in to comment.