gan-of-culture / jsurl

Golang port for jsurl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSURL

Go Go Report Card Go Reference

Golang port for jsurl

Example

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"strings"

	"github.com/gan-of-culture/jsurl"
)

type demoStruct struct {
	B interface{}
	C bool
	D int
	E string
}

func main() {
	flag.Parse()
	args := flag.Args()

	if len(args) < 1 {
		fmt.Println("you have to supply a jsurl string like ~(B~null~C~false~D~0~E~'hello*20world**203c)")
		return
	}

	if !strings.HasPrefix(args[0], "~(") {
		fmt.Println("jsurl string not found")
		return
	}

	test := &demoStruct{}

	jsurl.Parse(args[0], test)

	jsonData, _ := json.MarshalIndent(*test, "", "    ")
	fmt.Printf("%s\n", jsonData)
}

For more examples please take a look at the unittests

License

GPL-3.0

About

Golang port for jsurl

License:GNU General Public License v3.0


Languages

Language:Go 100.0%