-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplify error handling * remove obsolete dependencies * fix tests * update endpoint logic * first endpoint code
- Loading branch information
Showing
22 changed files
with
366 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
GO ?= go | ||
# On Windows OS is set. This makefile requires Linux or MacOS | ||
ifeq ($(OS),) | ||
SHELL := /bin/bash | ||
MAKE ?= make | ||
|
||
checktool = $(shell command -v $1 2>/dev/null) | ||
tool = $(if $(call checktool, $(firstword $1)), $1, @echo "$(firstword $1) was not found on the system. Please install it") | ||
|
||
GO ?= $(call checktool, go) | ||
GOTEST ?= $(GO) test | ||
GOTEST_ARGS ?= -timeout 2m -count 1 -cover | ||
|
||
GO_TOOLS= $(GO) run -modfile ./tools/go.mod | ||
|
||
.PHONY: test | ||
test: | ||
@$(GO) clean -testcache | ||
$(GOTEST) $(GOTEST_ARGS) ./... -v | ||
|
||
.PHONY: lint | ||
lint: | ||
@$(GO_TOOLS) github.com/golangci/golangci-lint/cmd/golangci-lint run -c .golangci.yml | ||
|
||
.PHONY: lint-fix | ||
lint-fix: | ||
@$(GO_TOOLS) github.com/golangci/golangci-lint/cmd/golangci-lint run -c .golangci.yml --fix | ||
@$(GO_TOOLS) github.com/golangci/golangci-lint/cmd/golangci-lint run -c .golangci.yml --fix | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
openapi: 3.0.3 | ||
openapi: 3.1.0 | ||
info: | ||
title: Room Service | ||
description: |- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var appConfig *Application | ||
|
||
type ( | ||
DatabaseType string | ||
LogStyle string | ||
) | ||
|
||
const ( | ||
Mysql DatabaseType = "mysql" | ||
Inmemory DatabaseType = "inmemory" | ||
|
||
Plain LogStyle = "plain" | ||
ECS LogStyle = "ecs" // default | ||
) | ||
|
||
type ( | ||
// Application is the root configuration type | ||
// that holds all other subconfiguration types | ||
Application struct { | ||
Service ServiceConfig `yaml:"service"` | ||
Server ServerConfig `yaml:"server"` | ||
Database DatabaseConfig `yaml:"database"` | ||
Security SecurityConfig `yaml:"security"` | ||
Logging LoggingConfig `yaml:"logging"` | ||
} | ||
|
||
// ServiceConfig contains configuration values | ||
// for service related tasks. E.g. URL to payment provider adapter | ||
ServiceConfig struct{} | ||
|
||
// ServerConfig contains all values for | ||
// http releated configuration | ||
ServerConfig struct { | ||
BaseAddress string `yaml:"address"` | ||
Port int `yaml:"port"` | ||
ReadTimeout int `yaml:"read_timeout_seconds"` | ||
WriteTimeout int `yaml:"write_timeout_seconds"` | ||
IdleTimeout int `yaml:"idle_timeout_seconds"` | ||
} | ||
|
||
// DatabaseConfig configures which db to use (mysql, inmemory) | ||
// and how to connect to it (needed for mysql only) | ||
DatabaseConfig struct { | ||
Use DatabaseType `yaml:"use"` | ||
Username string `yaml:"username"` | ||
Password string `yaml:"password"` | ||
Database string `yaml:"database"` | ||
Parameters []string `yaml:"parameters"` | ||
} | ||
|
||
// SecurityConfig configures everything related to security | ||
SecurityConfig struct { | ||
Fixed FixedTokenConfig `yaml:"fixed_token"` | ||
Oidc OpenIdConnectConfig `yaml:"oidc"` | ||
Cors CorsConfig `yaml:"cors"` | ||
RequireLogin bool `yaml:"require_login_for_reg"` | ||
} | ||
|
||
FixedTokenConfig struct { | ||
Api string `yaml:"api"` // shared-secret for server-to-server backend authentication | ||
} | ||
|
||
OpenIdConnectConfig struct { | ||
IdTokenCookieName string `yaml:"id_token_cookie_name"` // optional, but must both be set, then tokens are read from cookies | ||
AccessTokenCookieName string `yaml:"access_token_cookie_name"` // optional, but must both be set, then tokens are read from cookies | ||
TokenPublicKeysPEM []string `yaml:"token_public_keys_PEM"` // a list of public RSA keys in PEM format, see https://github.com/Jumpy-Squirrel/jwks2pem for obtaining PEM from openid keyset endpoint | ||
AdminGroup string `yaml:"admin_group"` // the group claim that supplies admin rights | ||
AuthService string `yaml:"auth_service"` // base url, usually http://localhost:nnnn, will skip userinfo checks if unset | ||
Audience string `yaml:"audience"` | ||
Issuer string `yaml:"issuer"` | ||
} | ||
|
||
CorsConfig struct { | ||
DisableCors bool `yaml:"disable"` | ||
AllowOrigin string `yaml:"allow_origin"` | ||
} | ||
|
||
// LoggingConfig configures logging | ||
LoggingConfig struct { | ||
Style LogStyle `yaml:"style"` | ||
Severity string `yaml:"severity"` | ||
} | ||
) | ||
|
||
// UnmarshalFromYamlConfiguration decodes yaml data from an `io.Reader` interface. | ||
func UnmarshalFromYamlConfiguration(file io.Reader) (*Application, error) { | ||
d := yaml.NewDecoder(file) | ||
d.KnownFields(true) // strict | ||
|
||
var conf Application | ||
|
||
if err := d.Decode(&conf); err != nil { | ||
return nil, err | ||
} | ||
|
||
appConfig = &conf | ||
return &conf, nil | ||
} | ||
|
||
func GetApplicationConfig() (*Application, error) { | ||
if appConfig == nil { | ||
return nil, errors.New("config was not yet loaded") | ||
} | ||
|
||
return appConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package controller | ||
|
||
// Controller is the service interface, which defines | ||
// the functions in the service layer of this application | ||
// | ||
// A type implementing this interface provides functionality | ||
// to interact between the web layer and the data layer | ||
type Controller interface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/apierrors/apierror_test.go → internal/errors/errors_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package apierrors | ||
package errors | ||
|
||
// TODO Write tests for apierror package |
Oops, something went wrong.