Skip to content

Instantly share code, notes, and snippets.

@arielsrv
Created November 27, 2022 12:10
Show Gist options
  • Save arielsrv/e1b94f0895a6dc363976cfa95be927cb to your computer and use it in GitHub Desktop.
Save arielsrv/e1b94f0895a6dc363976cfa95be927cb to your computer and use it in GitHub Desktop.

pets-api

CI Coverage Update release version.

Table of contents

Layers

layers.png

Command

asciicast

Project setup

Install the following dependencies

Required

Optional

If you want to browse api with SSL self-signed certificate

Script

brew install go-task/tap/go-task
brew install golangci-lint
go install github.com/oligot/go-mod-upgrade@latest
go install entgo.io/ent/cmd/ent@latest
brew install mkcert
brew install nginx

Tasks

Test

task test

Build

task build

Configuration

Environment configuration is based on Archaius Config, you should use a similar folder structure. SCOPE env variable in remote environment is required

└── config
    ├── config.yml (shared config)
    └── dev
        └── config.yml (for local development)
    └── prod (for remote environment)
        └── config.yml (base config)
        └── {environment}.config.yml (base config)

The SDK provides a simple configuration hierarchy

  • resources/config/config.properties (shared config)
  • resources/config/{environment}/config.properties (override shared config by environment)
  • resources/config/{environment}/{scope}.config.properties (override env and shared config by scope)

example test.pets-api.internal.com

└── config
    ├── config.yml                              third
    └── dev
        └── config.yml                          ignored
    └── prod
        └── config.yml (base config)            second
        └── test.config.yml (base config)       first
2022/11/20 13:24:26 INFO: Two files have same priority. keeping
    /resources/config/prod/test.config.yml value
2022/11/20 13:24:26 INFO: Configuration files:
    /resources/config/prod/test.config.yml,
    /resources/config/prod/config.yml,
    /resources/config/config.yml
2022/11/20 13:24:26 INFO: invoke dynamic handler:FileSource
2022/11/20 13:24:26 INFO: enable env source
2022/11/20 13:24:26 INFO: invoke dynamic handler:EnvironmentSource
2022/11/20 13:24:26 INFO: archaius init success
2022/11/20 13:24:26 INFO: ENV: prod, SCOPE: test
2022/11/20 13:24:26 INFO: create new watcher
2022/11/20 13:24:26 Listening on port 8080
2022/11/20 13:24:26 Open http://127.0.0.1:8080/ping in the browser

RestClient

RestPool and RestClient are dynamically created by config files.

# gitlab
rest:
  pool:
    default:
      pool:
        size: 20
        timeout: 2000
        connection-timeout: 5000
  client:
    gitlab:
      pool: default
var restClients = config.ProvideRestClients()

gitLabClient := gitlab.NewGitLabClient(restClients.Get("gitlab"))

Environment

SECRETS_STORE_GITLAB_TOKEN_KEY_NAME={gitlab_access_token} SECRETS_STORE_PROD_CONNECTION_STRING_KEY_NAME={mysql_connection_string}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment