microservice-core-go

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2025 License: Apache-2.0

README

Introduction

The microservice core is a small library which contains helper functions and basic setups for golang microservices. It's just a minimum set for messaging, rest and some helpers, but not so mightful as Goa

In the near future goa could be a better option to replace this.

Usage

How to use config?

  1. define config struct with all required values (include BaseConfig too!)
type exampleConfig struct {
    core.BaseConfig `mapstructure:",squash"`
    TestValue       string `mapstructure:"testValue"`
}

you can also define extra structs inside the config struct:

type exampleConfig struct {
    core.BaseConfig `mapstructure:",squash"`
    TestValue       string `mapstructure:"testValue"`
    OAuth           struct {
        ServerUrl    string `mapstructure:"serverUrl"`
        ClientId     string `mapstructure:"clientId"`
        ClientSecret string `mapstructure:"clientSecret"`
    } `mapstructure:"oAuth"`
}
  1. Create global config struct instance and load config with LoadConfig() function. Provide Prefix for ENV variables and map with default values
var ExampleConfig exampleConfig

func LoadConfig() error {
	err := core.LoadConfig("EXAMPLE", &ExampleConfig, getDefaults())
	if err != nil {
		return err
	}
	return nil
}

func getDefaults() map[string]any {
    return map[string]any{
    "testValue": "ciao",
    }
}

Note: The baseconfig can be also used by using envconfig. In this case the envconfig package is required and a envconfig processing before the start. But be aware that both variants in the same time can have interferences in variable loading (envconfig default can override viper loading and the other way arround).

Directories

Path Synopsis
pkg
cache
Package cache implements a client of the Cache service.
Package cache implements a client of the Cache service.
ctx
err
Package errors defines structured errors which can be used for nesting errors with propagation of error identifiers and their messages.
Package errors defines structured errors which can be used for nesting errors with propagation of error identifiers and their messages.
goadec
Package goadec provides Goa Request Decoders.
Package goadec provides Goa Request Decoders.
ocm
ptr
Package ptr contains utility functions for converting values to pointer values.
Package ptr contains utility functions for converting values to pointer values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL