58
GitHub - phasersec/san-go: SAN parser for Go & CLI
source link: https://github.com/phasersec/san-go
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
SAN-go
SAN (pronounce /seɪn/
, like sane) CLI and parser for Go.
Spec: https://astrocorp.net/san
Compatible with SAN version: v1.0.0
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK