commit a2f052f72b2e6baa4d27613c34f2fdec0499e590
Author: Mark Wilkerson <mark@markwilkerson.me>
Date: Thu, 25 Jan 2018 03:18:37 -0800
quick n dirty
Diffstat:
3 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Mark Wilkerson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
@@ -0,0 +1,18 @@
+# urlencode
+
+A command line utility to urlencode strings
+
+## Abstract
+
+I needed this so I wrote it in like 3 mins. Use at your own peril.
+
+
+## Install
+
+`go get github.com/markhuge/urlencode`
+
+## Usage
+
+`echo some string foo bar | urlencode`
+
+output: `some%20string%20foo%20bar`
diff --git a/main.go b/main.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "net/url"
+ "os"
+)
+
+func main() {
+ bytes, err := ioutil.ReadAll(os.Stdin)
+ // Quick n dirty
+ if err != nil {
+ panic(err)
+ }
+ // Get rid of that %0A at the end
+ bytes = bytes[:len(bytes)-1]
+
+ out := url.PathEscape(string(bytes))
+
+ fmt.Println(out)
+}