-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3c1c8b
commit 3db1a74
Showing
15 changed files
with
139 additions
and
144 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
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
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,10 @@ | ||
/* | ||
Package builtin is a helper to register all the built in formatters | ||
*/ | ||
package builtin | ||
|
||
import ( | ||
_ "github.com/drewstinnett/gout/v2/formats/gotemplate" | ||
_ "github.com/drewstinnett/gout/v2/formats/json" | ||
_ "github.com/drewstinnett/gout/v2/formats/yaml" | ||
) |
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
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,27 @@ | ||
package formats | ||
|
||
import "sort" | ||
|
||
type Creator func() Formatter | ||
|
||
var Formats = map[string]Creator{} | ||
|
||
// Add a new format creator | ||
func Add(name string, creator Creator) { | ||
Formats[name] = creator | ||
} | ||
|
||
// Names returns a slice of the names of the formatters | ||
func Names() []string { | ||
ret := []string{} | ||
for k := range Formats { | ||
ret = append(ret, k) | ||
} | ||
sort.Strings(ret) | ||
return ret | ||
} | ||
|
||
// Formatter interface that defines how a thing can be formatted for output | ||
type Formatter interface { | ||
Format(interface{}) ([]byte, error) | ||
} |
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,17 @@ | ||
package formats_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/drewstinnett/gout/v2/formats" | ||
_ "github.com/drewstinnett/gout/v2/formats/builtin" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBuiltinRegistry(t *testing.T) { | ||
require.Equal( | ||
t, | ||
[]string{"gotemplate", "json", "yaml"}, | ||
formats.Names(), | ||
) | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,8 @@ | ||
package gout | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
/* | ||
func TestBuiltInFormatters(t *testing.T) { | ||
require.Contains(t, BuiltInFormatters, "yaml") | ||
require.NotContains(t, BuiltInFormatters, "never-exist") | ||
} | ||
*/ |
Oops, something went wrong.