Files
golib/config
Nicolas JUHEL 61a73ba606 Package Certificates:
- fix bug with cert type marshall/unmarshall
- add old config to allow retro compatibility
- add new type function to retrieve a tls root ca cert instead of a slice of string to get root ca

Package HTTPCli:
- fix default DNS Mapper
- optimze global DNS Mapper
- fix non closing sub goroutine

Package HTTPCli/DNS-Mapper:
- change request function of Root CA with function of root ca cert instance
- add function to return a root ca cert from a function that return a slice of root ca string

Package Config/Components:
- httpcli: bump sub package of certificate, httpcli
- httpcli: adjust code following bump
- httpcli: change request function of Root CA with function of root ca cert instance
- httpcli: add function to return a root ca cert from a function that return a slice of root ca string
- tls: change request function of Root CA with function of root ca cert instance
- tls: add function to return a root ca cert from a function that return a slice of root ca string

Package IOUtils/mapCloser:
- fix bug with mapcloser not stopped
- optimize code & goroutine

Package Logger:
- rework mapCloser call
- optimize mapClaoser managment

Package Request:
- rework error managment
- using []byte instead of buffer to read response body
- add free capability
- optimize memory consumption

Package Socket / Server:
- add filtering error capability
- add params to specify a function called on each new connection and before using the connection
- the new function param allow to update the network incomming connection (like buffer, deadline...)
- rework some useless atomic to direct value to optimize code

Package Socket/Delim:
- rework to optimize memory & variable use
- remove capabilities of update the instance when running, prefert recreate new one if necessary

Other:
- bump dependencies
- minor bug / fix
2025-01-14 15:01:54 +01:00
..
2025-01-14 15:01:54 +01:00
2023-08-28 11:22:08 +02:00
2024-10-06 18:28:59 +02:00
2024-02-16 15:42:13 +01:00
2023-08-28 11:22:08 +02:00
2023-09-04 16:37:19 +02:00
2023-08-28 11:22:08 +02:00
2023-08-28 11:22:08 +02:00
2022-02-21 07:32:44 +01:00
2023-07-26 21:11:39 +02:00

Config pakcage

This package will make a global config management package for an app. This package work wil component who's will make the real intelligence of the config. For example, the main config file is not existing into this config, because is generated by the sum of all component config part.

Exmaple of implement

You can follow the initialization define into the cobra package Here we will define the intialization of the config package.

Main init of config :

Make a package's file to be called by yours application command or routers Into this file we will use some import

import (
    "fmt"
    "net/http"

    liberr "github.com/nabbar/golib/errors"
    libsts "github.com/nabbar/golib/status"
    liblog "github.com/nabbar/golib/logger"
    librtr "github.com/nabbar/golib/router"
	
    cmphea "github.com/nabbar/golib/config/components/head"
    cmphtp "github.com/nabbar/golib/config/components/http"
    cmplog "github.com/nabbar/golib/config/components/log"
    cmptls "github.com/nabbar/golib/config/components/tls"

    compkg "../pkg"
)

Some constant to prevents error on copy/paste :

const (
    ConfigKeyHead = "headers"
    ConfigKeyHttp = "servers"
    ConfigKeyLog  = "log"
    ConfigKeyTls  = "tls"
)

This function will init the libs and return the lib resource. This is an example, but you can create your own component to add it into you config. The config can have multi instance of same component type but with different config key. As That, you can for example define a TLS config for HTTP server, a TLS config for a client, ...

func SetConfig(lvl liblog.Level, handler map[string]http.Handler) {
    compkg.GetConfig().ComponentSet(ConfigKeyHead, cmphea.New())
    compkg.GetConfig().ComponentSet(ConfigKeyLog, cmplog.New(lvl, compkg.GetLogger))
    compkg.GetConfig().ComponentSet(ConfigKeyTls, cmptls.New())
    compkg.GetConfig().ComponentSet(ConfigKeyHttp, cmphtp.New(_ConfigKeyTls, _ConfigKeyLog, handler))
}

// This function will return the router header based of the component header stored into the config
func GetHeader() librtr.Headers {
    if cmp := cmphea.Load(compkg.GetConfig().ComponentGet, _ConfigKeyHead); cmp != nil {
        return cmp.GetHeaders()
    } else {
        GetLog().Fatal("component '%s' is not initialized", _ConfigKeyHead)
        return nil
    }
}

// This function will return the logger for the application. 
// If the component is not started, this function will return the root logger  
func GetLog() liblog.Logger {
    if !compkg.GetConfig().ComponentIsStarted() {
        return nil
    }

    if cmp := cmplog.Load(compkg.GetConfig().ComponentGet, _ConfigKeyLog); cmp != nil {
        return cmp.Log()
    } else {
        compkg.GetLogger().Error("component '%s' is not initialized", _ConfigKeyLog)
        return compkg.GetLogger()
    }
}

This function will connect the status package of golib with the httpserver package stored into the config :

// This function can be call by the implementation of Status Package to expose the status of the pool web server
// This function will update the status after each reload the pool web server.
func SetRouteStatus(sts libsts.RouteStatus) {
    compkg.GetConfig().RegisterFuncReloadAfter(func() liberr.Error {
        var cmp cmphtp.ComponentHttp

		// If component has not been started, skill the function
        if !compkg.GetConfig().ComponentIsStarted() {
            return nil
        }

		// if cannot access to the Http component, generate an error
        if cmp = cmphtp.Load(compkg.GetConfig().ComponentGet, ConfigKeyHttp); cmp == nil {
            return ErrorComponentNotInitialized.ErrorParent(fmt.Errorf("component '%s'", ConfigKeyHttp))
        }

		// Get the Pool Server
        pool := cmp.GetPool()
        pool.StatusRoute(_ConfigKeyHttp, GetRouteStatusMessage, sts)
		
		// Don't forget to update the component pool
        cmp.SetPool(pool)

        return nil
    })
}

To generate the config example, just call this function :

    compkg.GetConfig().DefaultConfig()

This function will associate the config Key with the component default config into a main buffer to return it. As that, config can be extended easily with many component and the config is automatically managed.