-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: use builders/formatters
- Loading branch information
Showing
8 changed files
with
444 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dynjson | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
type builder interface { | ||
build(fields []string) (formatter, error) | ||
} | ||
|
||
func makeBuilder(t reflect.Type) (builder, error) { | ||
switch t.Kind() { | ||
case reflect.Struct: | ||
return makeStructBuilder(t) | ||
case reflect.Ptr: | ||
if t.Elem().Kind() == reflect.Struct { | ||
return makePointerBuilder(t) | ||
} else { | ||
return makePrimitiveBuilder(t) | ||
} | ||
case reflect.Slice: | ||
if t.Elem().Kind() == reflect.Struct { | ||
return makeSliceBuilder(t) | ||
} else { | ||
return makePrimitiveBuilder(t) | ||
} | ||
default: | ||
return makePrimitiveBuilder(t) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.