Enhance gendoc for Generating Static and Dynamic Reference Configuration Files
This commit is contained in:
parent
3a461d2f23
commit
34d2a816c2
12 changed files with 1061 additions and 736 deletions
|
@ -5,13 +5,14 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/traefik/traefik/v2/pkg/collector/hydratation"
|
||||
"github.com/traefik/traefik/v2/pkg/config/static"
|
||||
)
|
||||
|
||||
func Test_createBody(t *testing.T) {
|
||||
var staticConfiguration static.Configuration
|
||||
|
||||
err := hydrate(&staticConfiguration)
|
||||
err := hydratation.Hydrate(&staticConfiguration)
|
||||
require.NoError(t, err)
|
||||
|
||||
buffer, err := createBody(&staticConfiguration)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package collector
|
||||
package hydratation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -17,7 +17,8 @@ const (
|
|||
defaultMapKeyPrefix = "name"
|
||||
)
|
||||
|
||||
func hydrate(element interface{}) error {
|
||||
// Hydrate hydrates a configuration.
|
||||
func Hydrate(element interface{}) error {
|
||||
field := reflect.ValueOf(element)
|
||||
return fill(field)
|
||||
}
|
||||
|
@ -41,9 +42,7 @@ func fill(field reflect.Value) error {
|
|||
return err
|
||||
}
|
||||
case reflect.Interface:
|
||||
if err := fill(field.Elem()); err != nil {
|
||||
return err
|
||||
}
|
||||
setTyped(field, defaultString)
|
||||
case reflect.String:
|
||||
setTyped(field, defaultString)
|
||||
case reflect.Int:
|
||||
|
@ -118,7 +117,7 @@ func makeKeyName(typ reflect.Type) string {
|
|||
case reflect.String,
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Bool, reflect.Float32, reflect.Float64:
|
||||
reflect.Bool, reflect.Float32, reflect.Float64, reflect.Interface:
|
||||
return defaultMapKeyPrefix
|
||||
default:
|
||||
return typ.Name()
|
|
@ -24,7 +24,7 @@ type Configuration struct {
|
|||
HTTP *HTTPConfiguration `json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" export:"true"`
|
||||
TCP *TCPConfiguration `json:"tcp,omitempty" toml:"tcp,omitempty" yaml:"tcp,omitempty" export:"true"`
|
||||
UDP *UDPConfiguration `json:"udp,omitempty" toml:"udp,omitempty" yaml:"udp,omitempty" export:"true"`
|
||||
TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"`
|
||||
TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"-" export:"true"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue