Skip to content

Commit

Permalink
feat: add url encode/decode cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudingcity committed Sep 5, 2020
1 parent 3e60e97 commit f91d8d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jwt-decode=#
| date-to-timestamp, d2t | Covert date to unix timestamp |
| jwt-decode | Decode [JWT](https://jwt.io/) |
| md5 | Computes the checksum |
| url-encode | Encode url |
| url-decode | Decode url |
| rand-string | Generate random string of given length (characters: a-z, A-Z, 0-9) |
| count | Get the characters length |
| camel-case | Coverts string to [camel case](https://en.wikipedia.org/wiki/Camel_case) |
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func commands() []*cobra.Command {
dateToTimestampCmd,
jwtDecodeCmd,
md5Cmd,
urlEncodeCmd,
urlDecodeCmd,
randStringCmd,
countCmd,
CamelCaseCmd,
Expand Down
32 changes: 32 additions & 0 deletions cmd/url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"
"net/url"

"github.com/spf13/cobra"
)

var urlEncodeCmd = &cobra.Command{
Use: "url-encode [text]",
Short: "Encode url",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(url.QueryEscape(args[0]))
},
}

var urlDecodeCmd = &cobra.Command{
Use: "url-decode [text]",
Short: "Decode url",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
s, err := url.QueryUnescape(args[0])
if err != nil {
fmt.Println("Invalid query")
}
fmt.Println(s)
},
}

0 comments on commit f91d8d2

Please sign in to comment.