Skip to content

Commit

Permalink
fix: moar linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcgrath13 committed Oct 10, 2024
1 parent b4ed350 commit a0b4ff6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 22 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
with:
go-version: '1.23.1'

- name: Check `go fmt`
run: test -z $(gofmt -l ./...)

- name: Install templ
run: go install github.com/a-h/templ/cmd/templ@latest

Expand All @@ -35,9 +32,6 @@ jobs:
with:
version: latest

- name: Run `go vet`
run: go vet ./...

- name: Build
run: go build -v ./...

Expand Down
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
linters:
enable:
- decorder
- durationcheck
- errchkjson
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gosec
- misspell
- prealloc
- predeclared
- reassign
- unconvert
- wastedassign
- whitespace
1 change: 1 addition & 0 deletions internal/app/fhir/r5/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func newXhtml(value string) *datatypespb.Xhtml {
return &datatypespb.Xhtml{Value: value}
}

//nolint:gosec
func newUnsignedInt(value int) *datatypespb.UnsignedInt {
return &datatypespb.UnsignedInt{Value: uint32(value)}
}
21 changes: 15 additions & 6 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ func (app *Application) getCodeSystemByID(w http.ResponseWriter, r *http.Request
}

var codeSystem *xo.CodeSystem
if id_type == "oid" {
switch id_type {
case Oid:
codeSystem, err = rp.GetCodeSystemByOID(r.Context(), id)
} else {
case Id:
codeSystem, err = rp.GetCodeSystemByID(r.Context(), id)
case Unknown:
customErrors.ServerError(w, r, customErrors.ErrInvalidId, app.logger)
}
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down Expand Up @@ -97,10 +100,13 @@ func (app *Application) getFHIRCodeSystemByID(w http.ResponseWriter, r *http.Req
}

var codeSystem *xo.CodeSystem
if id_type == "oid" {
switch id_type {
case Oid:
codeSystem, err = rp.GetCodeSystemByOID(r.Context(), id)
} else {
case Id:
codeSystem, err = rp.GetCodeSystemByID(r.Context(), id)
case Unknown:
customErrors.ServerError(w, r, customErrors.ErrInvalidId, app.logger)
}
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down Expand Up @@ -329,10 +335,13 @@ func (app *Application) getValueSetByID(w http.ResponseWriter, r *http.Request)
}

var valueSet *xo.ValueSet
if id_type == "oid" {
switch id_type {
case Oid:
valueSet, err = rp.GetValueSetByOID(r.Context(), id)
} else {
case Id:
valueSet, err = rp.GetValueSetByID(r.Context(), id)
case Unknown:
customErrors.ServerError(w, r, customErrors.ErrInvalidId, app.logger)
}

if err != nil {
Expand Down
23 changes: 16 additions & 7 deletions internal/app/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ import (
"github.com/CDCgov/phinvads-go/internal/errors"
)

func determineIdType(input string) (output string, err error) {
type IdType int

const (
Unknown IdType = iota
Oid IdType = iota
Id IdType = iota
)

func determineIdType(input string) (output IdType, err error) {
validId, _ := regexp.MatchString("^[a-zA-Z0-9-]+$", input)
validOid, _ := regexp.MatchString("^[0-9.]+$", input)

if validId {
return "id", nil
} else if validOid {
return "oid", nil
} else {
return "", errors.ErrInvalidId
switch {
case validId:
return Id, nil
case validOid:
return Oid, nil
default:
return Unknown, errors.ErrInvalidId
}
}
3 changes: 2 additions & 1 deletion internal/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func SetupApp(cfg *cfg.Config) *Application {

tlsConfig := &tls.Config{
CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
MinVersion: tls.VersionTLS12,
}

rp := rp.NewRepository(db)
Expand Down Expand Up @@ -75,7 +76,7 @@ func (app *Application) Run() {

app.logger.Error(err.Error())

defer app.db.Close()
app.db.Close()

os.Exit(1)
}
Expand Down
1 change: 0 additions & 1 deletion internal/database/models/codesystemconcept.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ func GetAllCodeSystemConcepts(ctx context.Context, db xo.DB) (*[]xo.CodeSystemCo
codeSystemConcepts = append(codeSystemConcepts, csc)
}
return &codeSystemConcepts, nil

}
1 change: 0 additions & 1 deletion internal/database/models/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,4 @@ func (r *Repository) GetValueSetVersionByVvsvVsvId(ctx context.Context, vvsv *xo

func (r *Repository) GetAllHotTopics(ctx context.Context) (*[]xo.HotTopic, error) {
return models.GetAllHotTopics(ctx, r.database)

}

0 comments on commit a0b4ff6

Please sign in to comment.