goutil

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2020 License: Apache-2.0

README

goutil

This a collection of go utilities for my own projects, if you are interested in the similar functionalities, you can have a quick access from this repo

util

Methods

  • IndexOfStrings(array []string, value string) int
  • LoadEnvs(file string) error

Install

go get github.com/ys-zhao/goutil/util

httputil

Methods

  • GetParam(r *http.Request, name string) string
  • GetParamBool(r *http.Request, name string) bool
  • GetParamInt(r *http.Request, name string) (int, error)
  • GetBodyJSON(r *http.Request, v interface{}) error
  • GetBodyXML(r *http.Request, v interface{}) error
  • GetBasicAuth(r *http.Request) (username, password string)
  • Request(method, url string, headers map[string]string, body io.Reader) (*http.Response, error)
  • RequestJSON(method, url string, headers map[string]string, req interface{}, res interface{}) (err error)
  • GetJSON(url string, headers map[string]string, res interface{}) error
  • PostJSON(url string, headers map[string]string, req interface{}, res interface{}) error
  • PutJSON(url string, headers map[string]string, req interface{}, res interface{}) error
  • DeleteJSON(url string, headers map[string]string, req interface{}, res interface{})
  • RequestXML(method, url string, headers map[string]string, req interface{}, res interface{}) (err error)
  • GetXML(url string, headers map[string]string, res interface{}) error
  • PostXML(url string, headers map[string]string, req interface{}, res interface{}) error
  • PutXML(url string, headers map[string]string, req interface{}, res interface{}) error
  • DeleteXML(url string, headers map[string]string, req interface{}, res interface{})

Install

go get github.com/ys-zhao/goutil/httputil

jsonutil

Methods

  • LoadReader(reader io.Reader, v interface{}) error
  • LoadFile(file string, v interface{}) error
  • SaveWriter(writer io.Writer, v interface{}) error
  • SaveWriterIndent(writer io.Writer, v interface{}, prefix, indent string)
  • SaveFile(file string, v interface{})
  • SaveFileIndent(file string, v interface{}, prefix, indent string)
  • ConvertToXML(jsonStr string, newOpts ...ConvertToXMLOption) (string, error)

Install

go get github.com/ys-zhao/goutil/jsonutil

xmlutil

Methods

  • LoadReader(reader io.Reader, v interface{}) error
  • LoadFile(file string, v interface{}) error
  • SaveWriter(writer io.Writer, v interface{}) error
  • SaveWriterIndent(writer io.Writer, v interface{}, prefix, indent string)
  • SaveFile(file string, v interface{})
  • SaveFileIndent(file string, v interface{}, prefix, indent string)
  • ConvertToJSON(jsonStr string, newOpts ...ConvertToXMLOption) (string, error)

Install

go get github.com/ys-zhao/goutil/xmlutil

s3util

Methods

  • Exists(ctx context.Context, s3Url string, cfg *Config) (exits bool, err error)
  • GetSize(ctx context.Context, s3Url string, cfg *Config) (size int64, err error)
  • DownloadFile(ctx context.Context, s3URL, fileURL string, cfg *Config) error
  • DownloadWriter(ctx context.Context, s3URL string, writer io.WriterAt, cfg *Config)
  • UploadFile(ctx context.Context, fileURL, s3URL, contentType, contentEncoding string, cfg *Config) error
  • UploadReader(ctx context.Context, reader io.Reader, s3URL, contentType, contentEncoding string, cfg *Config) error

Install

go get github.com/ys-zhao/goutil/s3util

Support

If you like the project, and want to support us to maintain and update the codes, you are welcome to donate with following button:

Donate

QR Code

Directories

Path Synopsis
zap
samples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL