dogescript / DSON

Description and website of the Doge Serialized Object Notation, a data-interchange textformat that is easy to read and write for Shiba Inu dogs.
29 stars 14 forks source link

dson.go: A DSON converter and serializer in Go #17

Closed muhammadmuzzammil1998 closed 6 years ago

muhammadmuzzammil1998 commented 6 years ago

dson.png

Build Status CodeFactor Go Report Card Codacy Badge Maintainability Test Coverage GitHub license Twitter

Hi, I wrote a new implementation for DSON standard in Go programming language. It's easy to use and implement in a project.

Kindly review https://github.com/muhammadmuzzammil1998/dsongo and add it to the list of libraries of DSON on the website.

dson.go can:

Examples


Install dson.go first

$ go get muzzammil.xyz/dsongo

Common imports

import (
    "fmt"

    "muzzammil.xyz/dsongo"
)

Encoding JSON into DSON

func main() {
    d := dson.Encode(`{"foo":"bar"}`)
    fmt.Println(d) // such "foo" is "bar" wow
}

Decoding DSON into JSON

func main() {
    j := dson.Decode(`such "foo" is "bar" wow`)
    fmt.Println(j) // {"foo":"bar"}
}

Validating DSON

func main() {
    if dson.Valid(`such "foo" is "bar" wow`) {
        fmt.Println("Valid DSON")
    } else {
        fmt.Println("Invalid DSON")
    }
}

Marshaling DSON

func main() {
    type ColorGroup struct {
        ID     int
        Name   string
        Colors []string
    }
    RedGroup := ColorGroup{
        ID:     1,
        Name:   "Reds",
        Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
    }
    r, err := dson.Marshal(RedGroup)
    if err == nil && dson.Valid(r) {
        fmt.Println(r) // such "ID" is 1! "Name" is "Reds". "Colors" is so "Crimson" and "Red" and "Ruby" also "Maroon" many wow
    }
}

Unmarshaling DSON

func main() {
    d := `so such "Name" is "Platypus" and "Order" is "Monotremata" wow and such "Name" is "Quoll" and "Order" is "Dasyuromorphia" wow many`
    if !dson.Valid(d) {
        fmt.Println("DSON is not valid")
        return
    }
    type Animal struct {
        Name  string
        Order string
    }
    var animals []Animal
    err := dson.Unmarshal(d, &animals)
    if err == nil {
        fmt.Printf("%+v", animals) // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
    }
}

Thanks!

muhammadmuzzammil1998 commented 6 years ago

I had to change it from dson.go to dsongo because go get got confused and thought dson.go is itself a go file. Redirects should work fine now.

AnEmortalKid commented 6 years ago

added #18 for this, is that the name you'd like or do you want something different for the Contributor part.

muhammadmuzzammil1998 commented 6 years ago

It's great 😄 Thanks!

muhammadmuzzammil1998 commented 6 years ago

@AnEmortalKid Please review #19

AnEmortalKid commented 6 years ago

Reviewed 19! I'll merge it and we can have @vpzomtrrfrt redeploy!

muhammadmuzzammil1998 commented 6 years ago

When will @vpzomtrrfrt redeploy?

muhammadmuzzammil1998 commented 6 years ago

I think there has been a confusion... The master branch is not up to date with the dsongo-by-muhammad branch thats why it doesn't show on the website. Please merge them.

I'll make an issue for it.

Thanks!