Skip to content

Instantly share code, notes, and snippets.

@juliendsv
Created May 12, 2014 08:35
Show Gist options
  • Save juliendsv/97ba3c6f64e4c84a197b to your computer and use it in GitHub Desktop.
Save juliendsv/97ba3c6f64e4c84a197b to your computer and use it in GitHub Desktop.
urllib in Go
$ go get github.com/kytrinyx/norwegish #for ex
$ git remote -v
origin https://github.com/kytrinyx/norwegish (fetch)
origin https://github.com/kytrinyx/norwegish (push)
# add your fork
$ git remote add fork git@github.com:you/norwegish.git
$ git remote -v
fork git@github.com:you/norwegish.git (fetch)
fork git@github.com:you/norwegish.git (push)
origin https://github.com/kytrinyx/norwegish (fetch)
origin https://github.com/kytrinyx/norwegish (push)
# Now you test should pass
# branching and PR
$ git checkout -b fix-capital-w-bug
$ git commit add -m "fixing"
$ git push fork fix_bug
# Then reset to master
$ git fetch origin
$ git reset --hard origin/master
mkdir -p $HOME/src/
export GOPATH=$HOME
export PATH=$PATH:$GOPATH/bin
package urllib
import (
"io"
"net/http"
"os"
"strings"
)
func Open(what string) (io.ReadCloser, error) {
if strings.HasPrefix(what, "http://") || strings.HasPrefix(what, "https://") {
res, err := http.Get(what)
if err != nil {
return nil, err
}
return res.Body, nil
}
return os.Open(what)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment