-
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.
Merge pull request #14 from drewstinnett/feature-plugin-redux
Feature: Make Formatters Pluggable (Again)
- Loading branch information
Showing
23 changed files
with
180 additions
and
215 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,12 @@ | ||
/* | ||
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/plain" | ||
_ "github.com/drewstinnett/gout/v2/formats/xml" | ||
_ "github.com/drewstinnett/gout/v2/formats/yaml" | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
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", "plain", "xml", "yaml"}, | ||
formats.Names(), | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.