mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-03 02:39:52 -06:00
config docs prototype
This commit is contained in:
27
accounts/cmd/helper/configdoc/main.go
Normal file
27
accounts/cmd/helper/configdoc/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"text/template"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/docs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.DefaultConfig()
|
||||
fields := docs.Display(*cfg)
|
||||
|
||||
content, err := ioutil.ReadFile("docs/templates/CONFIGURATION.tmpl")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tpl := template.Must(template.New("").Parse(string(content)))
|
||||
tpl.Execute(os.Stdout, fields)
|
||||
// for _, f := range fields {
|
||||
// fmt.Printf("%s %s = %v\t%s\n", f.Name, f.Type, f.DefaultValue, f.Description)
|
||||
// }
|
||||
}
|
||||
@@ -25,8 +25,8 @@ type Config struct {
|
||||
Repo Repo
|
||||
Index Index
|
||||
ServiceUser ServiceUser
|
||||
HashDifficulty int `env:"ACCOUNTS_HASH_DIFFICULTY"`
|
||||
DemoUsersAndGroups bool `env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"`
|
||||
HashDifficulty int `env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."`
|
||||
DemoUsersAndGroups bool `env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."`
|
||||
|
||||
Context context.Context `yaml:"-"`
|
||||
}
|
||||
|
||||
5
docs/templates/CONFIGURATION.tmpl
vendored
Normal file
5
docs/templates/CONFIGURATION.tmpl
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
| Name | Type | Default Value | Description |
|
||||
|------|------|---------------|-------------|
|
||||
{{- range .}}
|
||||
| {{.Name}} | {{.Type}} | {{.DefaultValue}} | {{.Description}}|
|
||||
{{- end }}
|
||||
38
ocis-pkg/docs/config.go
Normal file
38
ocis-pkg/docs/config.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type ConfigField struct {
|
||||
Name string
|
||||
DefaultValue string
|
||||
Type string
|
||||
Description string
|
||||
}
|
||||
|
||||
func Display(s interface{}) []ConfigField {
|
||||
t := reflect.TypeOf(s)
|
||||
v := reflect.ValueOf(s)
|
||||
|
||||
var fields []ConfigField
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
value := v.Field(i)
|
||||
|
||||
switch value.Kind() {
|
||||
default:
|
||||
desc := field.Tag.Get("desc")
|
||||
env, ok := field.Tag.Lookup("env")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
v := fmt.Sprintf("%v", value.Interface())
|
||||
fields = append(fields, ConfigField{Name: env, DefaultValue: v, Description: desc, Type: value.Type().Name()})
|
||||
case reflect.Struct:
|
||||
fields = append(fields, Display(value.Interface())...)
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
11
thumbnails/cmd/helper/configdoc/main.go
Normal file
11
thumbnails/cmd/helper/configdoc/main.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/docs"
|
||||
"github.com/owncloud/ocis/thumbnails/pkg/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.DefaultConfig()
|
||||
docs.Display(*cfg)
|
||||
}
|
||||
23
thumbnails/cmd/helper/defaultconfig/main.go
Normal file
23
thumbnails/cmd/helper/defaultconfig/main.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
"github.com/owncloud/ocis/accounts/pkg/config/parser"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
cfg := config.DefaultConfig()
|
||||
|
||||
parser.EnsureDefaults(cfg)
|
||||
parser.Sanitize(cfg)
|
||||
|
||||
b, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
Reference in New Issue
Block a user