Skip to content

Instantly share code, notes, and snippets.

@andykent
Created June 18, 2013 14:54
Show Gist options
  • Save andykent/5806033 to your computer and use it in GitHub Desktop.
Save andykent/5806033 to your computer and use it in GitHub Desktop.
Small go program to run through a list on stdin and URL unescape each line.
package main
import "fmt"
import "os"
import "net/url"
import "bufio"
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
result, err := url.QueryUnescape(scanner.Text())
if err != nil {
printError("PARSER", err)
return
}
fmt.Println(result)
}
if err := scanner.Err(); err != nil {
printError("STDIN", err)
}
}
func printError(msg string, err error) {
fmt.Fprintln(os.Stderr, "[" + msg + " ERROR] ", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment