Skip to content

➿ Serialize any custom type or convert any content to []byte or string, for Go Programming Language

License

Notifications You must be signed in to change notification settings

kataras/go-serializer

Repository files navigation


Build Status

Awesome GoLang

Report A+

License

Releases

Godoc

Chat



Serialize any custom type to []byte or string. Your custom serializers are, finally, organised.

Easy-to-use

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.

Installation

The only requirement is the Go Programming Language, at least v1.6.

$ go get -u github.com/kataras/go-serializer

Usage

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:

You can also navigate to the godocs.

FAQ

If you'd like to discuss this package, or ask questions about it, feel free to

Versioning

Current: v0.0.5

Read more about Semantic Versioning 2.0.0

People

The author of go-serializer is @kataras.

Contributing

If you are interested in contributing to the go-serializer project and add more serializers, please make a PR.

License

This project is licensed under the MIT License.

License can be found here.

About

➿ Serialize any custom type or convert any content to []byte or string, for Go Programming Language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages