Last active
April 27, 2018 17:47
-
-
Save prantoran/858c68b6cb6a6402b0623f58471300d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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