Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
sort configuration in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
imantung committed Dec 2, 2019
1 parent 85fb64c commit 77fb955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ Example of typical and scalable RESTful API Server for Go

| Name | Type | Default | Required |
|---|---|---|:---:|
|SERVER_DEBUG|bool|false||
|APP_ADDRESS|string|:8089|Yes|
|PG_DBNAME|string|typical-rest|Yes|
|PG_USER|string|postgres|Yes|
|PG_PASSWORD|string|pgpass|Yes|
|PG_HOST|string|localhost||
|PG_PASSWORD|string|pgpass|Yes|
|PG_PORT|int|5432||
|REDIS_HOST|string|localhost|Yes|
|REDIS_PORT|string|6379|Yes|
|REDIS_PASSWORD|string|redispass||
|PG_USER|string|postgres|Yes|
|REDIS_DB|int|0||
|REDIS_POOL_SIZE|int|20|Yes|
|REDIS_DIAL_TIMEOUT|Duration|5s|Yes|
|REDIS_READ_WRITE_TIMEOUT|Duration|3s|Yes|
|REDIS_IDLE_TIMEOUT|Duration|5m|Yes|
|REDIS_HOST|string|localhost|Yes|
|REDIS_IDLE_CHECK_FREQUENCY|Duration|1m|Yes|
|REDIS_IDLE_TIMEOUT|Duration|5m|Yes|
|REDIS_MAX_CONN_AGE|Duration|30m|Yes|
|APP_ADDRESS|string|:8089|Yes|
|REDIS_PASSWORD|string|redispass||
|REDIS_POOL_SIZE|int|20|Yes|
|REDIS_PORT|string|6379|Yes|
|REDIS_READ_WRITE_TIMEOUT|Duration|3s|Yes|
|SERVER_DEBUG|bool|false||

----

Expand Down
16 changes: 10 additions & 6 deletions pkg/typreadme/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/typical-go/typical-go/pkg/typbuildtool"
"github.com/typical-go/typical-go/pkg/typmodule"
"github.com/typical-go/typical-go/pkg/utility/coll"

"github.com/iancoleman/strcase"

Expand Down Expand Up @@ -42,14 +43,15 @@ func (Generator) Generate(ctx *typctx.Context, w io.Writer) (err error) {
}
}
md.WriteString("\n")

fields := fields(ctx)
if len(fields) > 0 {
keys, fieldMap := fields(ctx)
keys.Sort()
if len(keys) > 0 {
md.H3("Configuration")
md.WriteString("| Name | Type | Default | Required |\n")
md.WriteString("|---|---|---|:---:|\n")
for _, field := range fields {
for _, key := range keys {
var required string
field := fieldMap[key]
if field.Required {
required = "Yes"
}
Expand Down Expand Up @@ -85,12 +87,14 @@ func (Generator) Generate(ctx *typctx.Context, w io.Writer) (err error) {
return
}

func fields(ctx *typctx.Context) (fields []typcfg.Field) {
func fields(ctx *typctx.Context) (keys coll.Strings, m map[string]typcfg.Field) {
m = make(map[string]typcfg.Field)
for _, module := range ctx.AllModule() {
if configurer, ok := module.(typcfg.Configurer); ok {
prefix, spec, _ := configurer.Configure()
for _, field := range typcfg.Fields(prefix, spec) {
fields = append(fields, field)
m[field.Name] = field
keys.Append(field.Name)
}
}
}
Expand Down

0 comments on commit 77fb955

Please sign in to comment.