Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Mar 19, 2016
1 parent a957a52 commit 8af1043
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
9 changes: 8 additions & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ucfg

import "errors"
import (
"errors"
"fmt"
)

var (
ErrMissing = errors.New("field name missing")
Expand Down Expand Up @@ -30,3 +33,7 @@ func raise(err error) error {
// fmt.Println(string(debug.Stack()))
return err
}

func errDuplicateKey(name string) error {
return fmt.Errorf("duplicate field key '%v'", name)
}
31 changes: 31 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ucfg

type Option func(*options)

type options struct {
tag string
pathSep string
}

func StructTag(tag string) Option {
return func(o *options) {
o.tag = tag
}
}

func PathSep(sep string) Option {
return func(o *options) {
o.pathSep = sep
}
}

func makeOptions(opts []Option) options {
o := options{
tag: "config",
pathSep: "", // no separator by default
}
for _, opt := range opts {
opt(&o)
}
return o
}
34 changes: 0 additions & 34 deletions ucfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ type fields struct {
fields map[string]value
}

type Option func(*options)

type options struct {
tag string
pathSep string
}

var (
tConfig = reflect.TypeOf(Config{})
tConfigPtr = reflect.PtrTo(tConfig)
Expand Down Expand Up @@ -90,30 +83,3 @@ func (c *Config) PathOf(field, sep string) string {
}
return field
}

func StructTag(tag string) Option {
return func(o *options) {
o.tag = tag
}
}

func PathSep(sep string) Option {
return func(o *options) {
o.pathSep = sep
}
}

func makeOptions(opts []Option) options {
o := options{
tag: "config",
pathSep: "", // no separator by default
}
for _, opt := range opts {
opt(&o)
}
return o
}

func errDuplicateKey(name string) error {
return fmt.Errorf("duplicate field key '%v'", name)
}

0 comments on commit 8af1043

Please sign in to comment.