Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
<!-- Describe how this pull request changes the application -->
### What this pull request does
<!-- To help speed up the review process, please fill out the following sections -->
## What is the purpose of this pull request?


## What has changed?

<!-- Describe the problem or why the feature is necessary -->
### Why is this pull request necessary

## Notes for your reviewer


<!-- Checklist to help remember things to do before submitting the pull request. Delete items, that don't apply -->
### Checklist
## Risk assessment

- [ ] Commits have been cleaned
- [ ] Branch is rebased on top of base branch
<!--
MANDATORY.
Before filling out this section, thoroughly check where your code changes are being used,
and consider the impact of your changes, and expand on them so the reviewer has the context when reviewing the code

### User facing changelog
Example:
If you are changing a query for fetching data, consider what the data is used for.
If it is used in a critical workflow, i.e. deleting data, providing context for grading processes etc.,
then the risk is high, and reviewers need to be on edge.

```release-note
Example 2:
You could be changing a load condition for a component, which is used in the process of starting a flow, which is considered a critical workflow.
Again, expand below so reviewers have the full context of your changes.
-->

```
- [ ] No risk, the changes do not affect the existing functionality
- [ ] The changes could affect existing critical workflows, such as user management, grading processes or the
look/functionality of critical pages.
Further information below:
- [ ] The changes introduce critical workflows, such as user management, grading processes or the look/functionality
of critical pages. Further information below:

## Jira links

>

## Clockify key

>

## New language variables
```list_of_new_variables

```
- [ ] Terms uploaded

[For instructions on uploading language terms](https://github.com/UNIwise/developer-conventions/blob/master/i18n/coreUploadingTerms.md)

[Read more about Pull Request best practices here](https://github.com/UNIwise/developer-conventions/blob/master/general/git.md)

<!-- Example:
"Based on user feedback, the animation should be more subtle"

"Changed the starting color to lessen the color change during animation
Changed the starting size to lessen the size change during animation
See attached gif"

"I also fixed a couple of syntax errors I found while working on this"
-->
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ on:
push:
branches:
- master
- develop
- release/*
- feature/*
- hotfix/*

jobs:
golang:
uses: UNIwise/workflows/.github/workflows/golang.yaml@master
secrets: inherit
with:
go-version: 1.19
golangci-lint-version: v1.61.0
go-version: 1.26
golangci-lint-version: v2.11.4
103 changes: 91 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,92 @@
version: "2"

linters:
enable-all: true
disable:
- wsl
- gochecknoglobals
- exhaustivestruct
- wrapcheck

# Deprecated
- scopelint
- golint
- maligned
- interfacer
default: none
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- copyloopvar
- dogsled
- dupword
- embeddedstructfieldcheck
- errcheck
- errname
- exhaustive
- exptostd
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- godot
- gomoddirectives
- govet
- inamedparam
- ineffassign
- intrange
- iotamixing
- lll
- misspell
- modernize
- musttag
- nestif
- nlreturn
- nolintlint
- nonamedreturns
- nosprintfhostport
- paralleltest
- perfsprint
- predeclared
- promlinter
- protogetter
- staticcheck
- tagalign
- testifylint
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
- wsl_v5
exclusions:
generated: strict
rules:
- path: _test\.go
linters:
- errcheck
- dupl
- gosec
- linters:
- errcheck
source: "^\\s*defer\\s+"
settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 150
paralleltest:
ignore-missing-subtests: true
tagalign:
strict: true
testifylint:
disable:
- require-error

formatters:
enable:
- gofmt
- gofumpt
- goimports
- golines
settings:
gofumpt:
extra-rules: true
golines:
max-len: 150

issues:
fix: true

run:
timeout: 5m
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
############################
# STEP 1 build base
############################
FROM golang:1.19-alpine3.17 as build-base
FROM golang:1.26-alpine3.23 as build-base
RUN apk add --update --no-cache git ca-certificates build-base
WORKDIR /build
ENV GO111MODULE=on
COPY go.mod .
COPY go.sum .
RUN go mod download -x

############################
# STEP 2 image base
############################
FROM alpine:3.17 as image-base
FROM alpine:3.23 as image-base
WORKDIR /app
COPY --from=build-base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/app/parrot", "serve"]
Expand Down
18 changes: 11 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -28,15 +28,18 @@ import (

var cfgFile string

const asciiart string = "ICAgICAoXA0KICAgICggIFwgIC8obylcDQogICAgKCAgIFwvICAoKS8gLykNCiAgICAgKCAgIGA7LikpJyIuKQ0KICAgICAgYCgvLy8vLy4tJw0KICAgPT09PT0pKT0pKT09PSgpDQogICAgIC8vLycNCiAgICAvLw0KICAgJw=="
const asciiart string = "ICAgICAoXA0KICAgICggIFwgIC8obylcDQogICAgKCAgIFwvICAoKS8gLykNCiAgICAgKCAgIGA7LikpJyIuKQ0KICAgICAgYCgvLy8vLy4tJw0KICAgPT09PT0pKT0pKT09PSgpDQogICAgIC8vLycNCiAgICAvLw0KICAgJw==" //nolint:lll

func ascii() string {
b, _ := base64.StdEncoding.DecodeString(asciiart)
b, err := base64.StdEncoding.DecodeString(asciiart)
if err != nil {
return ""
}

return string(b)
}

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "parrot",
Short: "Your friendly neighborhood Poeditor pull-through-cache",
Expand All @@ -54,7 +57,7 @@ func Execute() {
cobra.CheckErr(rootCmd.Execute())
}

// nolint:gochecknoinits
//nolint:gochecknoinits
func init() {
cobra.OnInitialize(initConfig)

Expand All @@ -76,10 +79,11 @@ func initConfig() {
viper.SetConfigName(".parrot")
}

godotenv.Load(".env")
_ = godotenv.Load(".env") //nolint:errcheck

viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
viper.ReadInConfig()
_ = viper.ReadInConfig() //nolint:errcheck
}
13 changes: 10 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -63,7 +63,7 @@ const (
confAPIToken = "api.token"
)

// serveCmd represents the serve command
// serveCmd represents the serve command.
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the parrot caching server",
Expand All @@ -90,6 +90,7 @@ by caching exports from poeditor`,
port := viper.GetInt(confServerPort)

logger.Infof("Server listening at :%d", port)

go func() {
if err := server.Start(port); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Fatal("shutting down server")
Expand All @@ -98,6 +99,7 @@ by caching exports from poeditor`,

if viper.GetBool(confPrometheusEnabled) {
logger.Infof("Prometheus metrics exposed at :%d%s", viper.GetInt(confPrometheusPort), viper.GetString(confPrometheusPath))

go func() {
logger.Fatal(metrics.Start(viper.GetString(confPrometheusPath), viper.GetInt(confPrometheusPort)))
}()
Expand All @@ -106,15 +108,17 @@ by caching exports from poeditor`,
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit

ctx, cancel := context.WithTimeout(context.Background(), viper.GetDuration(confServerGrace))
defer cancel()

if err := server.Shutdown(ctx); err != nil {
logger.Fatal(err)
}
},
}

// nolint:gochecknoinits
//nolint:gochecknoinits
func init() {
cDir, err := os.UserCacheDir()
if err != nil {
Expand Down Expand Up @@ -148,8 +152,10 @@ func instantiateLogger() *logrus.Logger {
lvl, err := logrus.ParseLevel(viper.GetString(confLogLevel))
if err != nil {
logger.WithError(err).Warnf("Could not parse log level '%s' defaulting to INFO", viper.GetString(confLogLevel))

lvl = logrus.InfoLevel
}

logger.SetLevel(lvl)

switch viper.GetString(confLogFormat) {
Expand All @@ -161,6 +167,7 @@ func instantiateLogger() *logrus.Logger {
logger.Warnf("Did not understand log format '%s'. Defaulting to json format", viper.GetString(confLogFormat))
logger.SetFormatter(&logrus.JSONFormatter{})
}

return logger
}

Expand Down
Loading