Browse Source

Add linters

pull/1/head
Jonas Franz 6 years ago
parent
commit
1149c45437
No known key found for this signature in database
GPG Key ID: 7293A220B7C38080
  1. 9
      .drone.yml
  2. 25
      .golangci
  3. 13
      Makefile
  4. 5
      cmd/run.go
  5. 6
      config/config.go
  6. 1
      models/repository.go
  7. 1
      models/user.go
  8. 1
      utils/secret.go
  9. 1
      web/router.go

9
.drone.yml

@ -0,0 +1,9 @@
kind: pipeline
name: default

steps:
- name: lint
image: golang:1.12
commands:
- make lint
- make golangci-lint

25
.golangci

@ -0,0 +1,25 @@
linters:
enable:
- gosimple
- deadcode
- typecheck
- govet
- errcheck
- staticcheck
- unused
- structcheck
- varcheck
- golint
- dupl
- gofmt
- misspell
- gocritic
enable-all: false
disable-all: true
fast: false

linters-settings:
gocritic:
disabled-checks:
- ifElseChain
- singleCaseSwitch # Every time this occured in the code, there was no other way.

13
Makefile

@ -0,0 +1,13 @@
.PHONY: golangci-lint
golangci-lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.16.0; \
fi
golangci-lint run

.PHONY: lint
lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u golang.org/x/lint/golint; \
fi
golint ./...

5
cmd/run.go

@ -21,12 +21,13 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )


// CmdRun is the command to start the webserver
var CmdRun = cli.Command{ var CmdRun = cli.Command{
Action: run, Action: run,
Name: "run", Name: "run",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "address", Name: "address",
Value: ":3030", Value: ":3030",
}, },
}, },

6
config/config.go

@ -39,6 +39,7 @@ func (k Key) setDefault(defaultValue interface{}) {
viper.SetDefault(string(k), defaultValue) viper.SetDefault(string(k), defaultValue)
} }


// This block contains all config keys
const ( const (
DaysUntilStale Key = "daysUntilStale" DaysUntilStale Key = "daysUntilStale"
DaysUntilClose Key = "daysUntilClose" DaysUntilClose Key = "daysUntilClose"
@ -61,6 +62,7 @@ const (
SessionSecret Key = "session_secret" SessionSecret Key = "session_secret"
) )


// SetupConfig fills all default values, reads the config and/or writes the default config.
func SetupConfig() error { func SetupConfig() error {
DaysUntilStale.setDefault(60) DaysUntilStale.setDefault(60)
DaysUntilClose.setDefault(7) DaysUntilClose.setDefault(7)
@ -90,7 +92,9 @@ func SetupConfig() error {
viper.AddConfigPath(".") viper.AddConfigPath(".")
if err := viper.SafeWriteConfigAs("config.yml"); err != nil { if err := viper.SafeWriteConfigAs("config.yml"); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = viper.WriteConfigAs("config.yml") if err := viper.WriteConfigAs("config.yml"); err != nil {
return err
}
} }
} }
return viper.ReadInConfig() return viper.ReadInConfig()

1
models/repository.go

@ -16,6 +16,7 @@


package models package models


// Repository represents a Gitea repository indexed at the local database
type Repository struct { type Repository struct {
ID int64 `xorm:"pk"` ID int64 `xorm:"pk"`
Owner string `xorm:"unique(owner_name)"` Owner string `xorm:"unique(owner_name)"`

1
models/user.go

@ -18,6 +18,7 @@ package models


import "golang.org/x/oauth2" import "golang.org/x/oauth2"


// User represents a signed in oauth2 gitea user saved in a session
type User struct { type User struct {
ID int64 ID int64
Username string Username string

1
utils/secret.go

@ -21,6 +21,7 @@ import (
"encoding/base64" "encoding/base64"
) )


// NewSecret will generate a random string of the given length
func NewSecret(length int) (string, error) { func NewSecret(length int) (string, error) {
secret := make([]byte, length) secret := make([]byte, length)
if _, err := rand.Read(secret); err != nil { if _, err := rand.Read(secret); err != nil {

1
web/router.go

@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )


// StartServer will start the webserver at the given addresses
func StartServer(addr ...string) error { func StartServer(addr ...string) error {
r := gin.Default() r := gin.Default()
store := cookie.NewStore([]byte(config.SessionSecret.Get().(string))) store := cookie.NewStore([]byte(config.SessionSecret.Get().(string)))

Loading…
Cancel
Save