Created
May 12, 2014 08:35
-
-
Save juliendsv/97ba3c6f64e4c84a197b to your computer and use it in GitHub Desktop.
urllib in Go
This file contains 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
$ 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 |
This file contains 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
mkdir -p $HOME/src/ | |
export GOPATH=$HOME | |
export PATH=$PATH:$GOPATH/bin |
This file contains 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 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