Created
June 18, 2013 14:54
-
-
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.
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 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