Serialize any custom type to []byte or string. Your custom serializers are, finally, organised.
While providing robust set of features, simple to understand.
Built'n supported serializers:
Go here to learn how you can create and use your own custom Serializer.
This package is already used by Iris web framework and Q web framework, examples here.
The only requirement is the Go Programming Language, at least v1.6.
$ go get -u github.com/kataras/go-serializer
package main
import (
"github.com/kataras/go-serializer"
"github.com/kataras/go-serializer/markdown"
)
func main() {
markdownSerializer := markdown.New()
serializer.For("markdown", markdownSerializer)
result, err := serializer.SerializeToString("markdown", "## Hello")
// Optional third parameter is a map[string]interface{}, which is any runtime options for the serializers registered to 'markdown' key
println(result)
}
explanation
Create your own serializer or use one of the project's built'n serializers, in this case we will use the markdown serializer will receive markdown content as string and return the HTML form of them
markdownSerializer := markdown.New()
Learn how to create your own custom serializer go to the serializer_test.go, it's just one function.
mySerializers := serializer.Serializers{}
mySerializers.For("key", markdownSerializer)
Add the serializer to a custom key, using the default Serializers{}. It supports more than one serializer for each key
serializer.For("markdown", markdownSerializer)
Serialize something with the registered serializers by a key. If more than one Serializer is registered to the same key then the final result will be the results of all of its(key's) serializers
result, err := serializer.SerializeToString("markdown", "## Hello")
.Serialize(...) returns []byte, SerializeToString(...) returns string, they're the same use that you need
Print the result, will be just a <h2>Hello</h2>
println(result)
For more, please read each of the Serializers you want to use, built'n supported are:
- JSON
- JSONP
- XML
- Markdown
- Text (exists for your learning curve)
- Binary Data (exists for your learning curve)
You can also navigate to the godocs.
If you'd like to discuss this package, or ask questions about it, feel free to
- Explore these questions.
- Post an issue or idea here.
- Navigate to the Chat.
Current: v0.0.5
Read more about Semantic Versioning 2.0.0
- http://semver.org/
- https://en.wikipedia.org/wiki/Software_versioning
- https://wiki.debian.org/UpstreamGuide#Releases_and_Versions
The author of go-serializer is @kataras.
If you are interested in contributing to the go-serializer project and add more serializers, please make a PR.
This project is licensed under the MIT License.
License can be found here.