SAN parser for Go & CLI - the Simple And Needed TOML/YAML alternative
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

SAN-go

GoDoc Build Status GitHub release

SAN (pronounce /seɪn/, like sane) CLI and parser for Go.

Spec: https://astrocorp.net/san

Compatible with SAN version: v1.0.0

  1. Installation
  2. Library
  3. CLI

Installation

go get -u github.com/phasersec/san-go/...

Library

package main

import (
	"fmt"

	"github.com/phasersec/san-go"
)

type D struct {
	A string
}

type C struct {
	A int64 `san:"a"`
	D []D   `san:"d"`
}

type S struct {
	A string  `san:"a"`
	B []int64 `san:"b"`
	C C       `san:"c"`
}

func main() {
	str1 := `
a = "a"
b = [1, 2]
c = { a = 1, d = [ { a = "3.3" }, { a = "xxx" } ] }
`
	var s S

	err := san.Unmarshal([]byte(str1), &s)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%#v\n\n", s)

	b, err := san.Marshal(s)
	if err != nil {
		panic(err)
	}
	fmt.Print(string(b))
}
go run main.go
main.S{A:"a", B:[]int64{1, 2}, C:main.C{A:1, D:[]main.D{main.D{A:"3.3"}, main.D{A:"xxx"}}}}

a = "a"
b = [
  1,
  2,
]
c = {
  a = 1

  d = [
    {
      A = "3.3"
    },
    {
      A = "xxx"
    },
  ]
}

CLI

This repo also contains a CLI helper for the SAN format. It can be installed with the following command:

$ go get -u github.com/phasersec/san-go/...

Examples

Convert a [.toml, .json, .yml, .yaml] file to a .san

$ san convert ../config.yml # wil create ../config.san

Automatically formats a SAN file

$ san fmt config.san

Check a .san file validity

$ san validate config.san