initial commit
This commit is contained in:
8
utils/panicOnError.go
Normal file
8
utils/panicOnError.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package utils
|
||||
|
||||
// PanicOnError will panic if err goven is not nil
|
||||
func PanicOnError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
21
utils/readLine.go
Normal file
21
utils/readLine.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var rd *bufio.Reader
|
||||
|
||||
// ReadLine reads a line from stdin and strips newline from the end
|
||||
func ReadLine() string {
|
||||
if rd == nil {
|
||||
rd = bufio.NewReader(os.Stdin)
|
||||
}
|
||||
|
||||
str, err := rd.ReadString('\n')
|
||||
PanicOnError(err)
|
||||
|
||||
return strings.TrimRight(str, "\r\n")
|
||||
}
|
||||
16
utils/unmarshalFromResponse.go
Normal file
16
utils/unmarshalFromResponse.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// UnmarshalFromResponse will unmarshal json from response body
|
||||
func UnmarshalFromResponse(response *http.Response, v interface{}) {
|
||||
responseBody, err := ioutil.ReadAll(response.Body)
|
||||
PanicOnError(err)
|
||||
|
||||
err = json.Unmarshal(responseBody, &v)
|
||||
PanicOnError(err)
|
||||
}
|
||||
Reference in New Issue
Block a user