Giter Club home page Giter Club logo

oxygen's Introduction

oxygen

https://img.shields.io/github/v/tag/gromey/oxygen https://img.shields.io/github/license/gromey/oxygen

oxygen is a library designed to create custom formatters like JSON, XML.

Installation

oxygen can be installed like any other Go library through go get:

go get github.com/gromey/oxygen

Or, if you are already using Go Modules, you may specify a version number as well:

go get github.com/gromey/oxygen@latest

Getting Started

After you get the library, you must generate your type using the following command:

go run github.com/gromey/oxygen/cmd/generate -n=name

In this command, you must specify a name of your new formatter. The name must contain only letters and be as simple as possible.

This command generates a package with the name specified in the generate command. The package will contain two files asserts.go and tag.go.

WARNING: DO NOT EDIT asserts.go.

tag.go will contain the base implementation of your new formatter. You need to implement three functions Parse, Encode and Decode.

Parse function gets the value of the tag and a pointer to your tag structure, here you need to parse the tag into a tag structure. If you don't use tags, just remove this method.

Encode function receives a value encoded into a byte array, if exists a tag struct and a field name, here you can do additional encoding otherwise just remove this method.

Decode function receives an encoded data, if exists a tag struct and a field name, here you must find a byte array representing a value for the current field and perform initial decoding if necessary before returning this byte array.
You can change the input data and for the next field you will receive the data in a modified form, however this will not affect the original data, since you are working with a copy of the data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.