Skip to content

Instantly share code, notes, and snippets.

@prantoran
Last active April 27, 2018 17:47
Show Gist options
  • Save prantoran/858c68b6cb6a6402b0623f58471300d6 to your computer and use it in GitHub Desktop.
Save prantoran/858c68b6cb6a6402b0623f58471300d6 to your computer and use it in GitHub Desktop.
package printer
import (
"io/ioutil"
"net/http"
)
type Printer interface {
Print(s string) (*Resp, error)
}
type Resp struct {
Body, Status string
}
type HomePrinter struct {
URL string
}
func (p *HomePrinter) Print(s string) (*Resp, error) {
addr := p.URL + "?v=" + s
res, err := http.Get(addr)
if err != nil {
return nil, err
}
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
return &Resp{Body: string(bodyBytes), Status: res.Status}, nil
}
func New(URL string) *HomePrinter {
return &HomePrinter{URL}
}
var Cur Printer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment