base64

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2020 License: BSD-3-Clause Imports: 3 Imported by: 67

README

go-base64

A raw base64 URL encoding library for JSON.

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Usage

base64 Provides a convenient way to read and write raw (no padding) base64 URL values.

package main

import (
	"encoding/json"
	"fmt"

	"github.com/manifoldco/go-base64"
)

type Example struct {
	Name        string        `json:"name"`
	Data        *base64.Value `json:"data"`
	RegularData []byte        `json:"regular"`
}

func main() {
	sample := []byte{0xF, 0xEE, 0xD, 0xC, 0x0D}
	e := &Example{
		Name:        "test data",
		Data:        base64.New(sample),
		RegularData: sample,
	}

	o, _ := json.MarshalIndent(e, "", "  ")
	fmt.Println(string(o))
}

Outputs:

{
  "name": "test data",
  "data": "D-4NDA0",
  "regular": "D+4NDA0="
}

Documentation

Overview

Package base64 provides a byte slice type that marshals into json as a raw (no padding) base64url value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

type Value []byte

Value is a base64url encoded json object,

func New

func New(b []byte) *Value

New returns a pointer to a Value, cast from the given byte slice. This is a convenience function, handling the address creation that a direct cast would not allow.

func NewFromString

func NewFromString(encoded string) (*Value, error)

NewFromString returns a Value containing the decoded data in encoded.

func (*Value) MarshalJSON

func (bv *Value) MarshalJSON() ([]byte, error)

MarshalJSON returns the ba64url encoding of bv for JSON representation.

func (*Value) String

func (bv *Value) String() string

func (*Value) UnmarshalJSON

func (bv *Value) UnmarshalJSON(b []byte) error

UnmarshalJSON sets bv to the bytes represented in the base64url encoding b.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL