Skip to content

Commit

Permalink
Merge pull request #101 from ITU-DevOps-N/89-Static_analysis_tool
Browse files Browse the repository at this point in the history
#89 Static analysis tool
  • Loading branch information
emilravn committed Mar 24, 2022
2 parents 7285afe + 997770e commit faaba86
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 24 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Static analysis

on:
pull_request:
branches: [ develop, main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Verify dependencies
run: go mod download && go mod verify

- name: Build web
run: go build -o go-minitwit src/main.go

- name: Build api
run: go build -o go-minitwit-api api/api.go

- name: Run go vet on web
run: go vet src/main.go

- name: Run go vet on api
run: go vet api/api.go

- name: Install GoKart
run: go install github.com/praetorian-inc/gokart@latest

- name: Run GoKart on web
run: gokart scan src/

- name: Run GoKart on api
run: gokart scan api/

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck on web
run: staticcheck src/main.go

- name: Run staticcheck on api
run: staticcheck api/api.go

- name: Install errcheck
run: go install github.com/kisielk/errcheck@latest

- name: Run errcheck on web
run: errcheck src/main.go

- name: Run errcheck on api
run: errcheck api/api.go

- name: Install go tools
run: go install golang.org/x/tools/...@latest

- name: Run gotype on web
run: gotype -e src/main.go

- name: Run gotype on api
run: gotype -e api/api.go
14 changes: 9 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func SetupDB() {
dsn := "minitwit:" + os.Getenv("DB_PASS") + "@tcp(db:3306)/minitwit?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
fmt.Printf("Error: %s", err.Error())
bugsnag.Notify(fmt.Errorf("Failed to connect to database:\t" + err.Error()))
panic("Failed to connect to database.")
panic(err)
}
err1 := db.AutoMigrate(&model.User{}, &model.Message{}, &model.Follow{})
if err1 != nil {
panic(err1)
}
db.AutoMigrate(&model.User{}, &model.Message{}, &model.Follow{})
DB = db
}

Expand Down Expand Up @@ -366,5 +367,8 @@ func main() {
router.GET("/metrics", prometheusHandler())
getGinMetrics(router)

router.Run(":8080")
err := router.Run(":8080")
if err != nil {
panic(err)
}
}
35 changes: 16 additions & 19 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import (

// All of the below imports share the same package i.e. we could have
// used the follow to access all functions.

follow "github.com/ITU-DevOps-N/go-minitwit/src/controller"
login "github.com/ITU-DevOps-N/go-minitwit/src/controller"

messages "github.com/ITU-DevOps-N/go-minitwit/src/controller"
registration "github.com/ITU-DevOps-N/go-minitwit/src/controller"
ui "github.com/ITU-DevOps-N/go-minitwit/src/controller"
controller "github.com/ITU-DevOps-N/go-minitwit/src/controller"
database "github.com/ITU-DevOps-N/go-minitwit/src/database"
model "github.com/ITU-DevOps-N/go-minitwit/src/models"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -89,20 +83,23 @@ func main() {
router.Static("/web/static", "./src/web/static")

database.SetupDB()
router.GET("/", messages.Timeline)
router.GET("/public_timeline", ui.Timeline)
router.GET("/user_timeline", ui.UserTimeline)
router.GET("/register", registration.Register)
router.POST("/register", registration.SignUp)
router.GET("/login", login.LoginPage)
router.POST("/login", login.Login)
router.GET("/logout", login.Logout)
router.GET("/follow", follow.Follow)
router.GET("/unfollow", follow.Unfollow)
router.POST("/add_message", messages.AddMessage)
router.GET("/", controller.Timeline)
router.GET("/public_timeline", controller.Timeline)
router.GET("/user_timeline", controller.UserTimeline)
router.GET("/register", controller.Register)
router.POST("/register", controller.SignUp)
router.GET("/login", controller.LoginPage)
router.POST("/login", controller.Login)
router.GET("/logout", controller.Logout)
router.GET("/follow", controller.Follow)
router.GET("/unfollow", controller.Unfollow)
router.POST("/add_message", controller.AddMessage)

router.GET("/metrics", prometheusHandler())
getGinMetrics(router)

router.Run(":80")
err := router.Run(":80")
if err != nil {
panic(err)
}
}

0 comments on commit faaba86

Please sign in to comment.