Giter VIP home page Giter VIP logo

gread's Introduction

gread godocs Github Actions Coverage Status Go Report Card Sourcegraph

Go module for reading from anything that implements io.Reader

Installing

$ go get github.com/stevenferrer/gread

Example

package main

import (
    "fmt"
    "log"
    "math"
    "strings"

    "github.com/stevenferrer/gread"
)

func main() {
    s := fmt.Sprintf("%v %d %v %v %v %v\nanother line\nhello",
        math.MaxInt32,
        math.MaxInt64,
        math.MaxUint32,
        uint64(math.MaxUint64),
        math.MaxFloat32,
        math.MaxFloat64,
    )
    
    // Create a new `gread.Reader`
    reader := gread.NewReader(strings.NewReader(s))
    
    i32, err := reader.NextInt32()
    checkErr(err)
    fmt.Printf("%T is %d\n\n", i32, i32)

    i64, err := reader.NextInt64()
    checkErr(err)
    fmt.Printf("%T is %d\n\n", i64, i64)

    ui32, err := reader.NextUint32()
    checkErr(err)
    fmt.Printf("%T is %d\n\n", ui32, ui32)

    ui64, err := reader.NextUint64()
    checkErr(err)
    fmt.Printf("%T is %d\n\n", ui64, ui64)

    f32, err := reader.NextFloat32()
    checkErr(err)
    fmt.Printf("%T is %f\n\n", f32, f32)

    f64, err := reader.NextFloat64()
    checkErr(err)
    fmt.Printf("%T is %f\n", f64, f64)

    w, err := reader.NextWord()
    checkErr(err)
    fmt.Printf("\nword1 is %q\n", w)
    w, err = reader.NextWord()
    checkErr(err)
    fmt.Printf("word2 is %q\n", w)

    l, err := reader.NextLine()
    checkErr(err)
    fmt.Printf("\nline is %q\n", l)
}

func checkErr(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

Contributing

Please feel free to improve this by openning an issue or submitting a PR

gread's People

Contributors

nochso avatar stevenferrer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

nochso

gread's Issues

prefix methods with Next

I think it would be better if the methods would be more descriptive about what they're doing, thus should be prefixed with Next (e.g. NextIn32, NextWord, NextLine, etc.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.