Skip to content

Commit

Permalink
feat: add base64 scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudingcity committed Sep 13, 2020
1 parent 32b7cf6 commit 0e9d9ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jwt-decode=#
| md5 | Computes the checksum |
| url-encode | Encode url |
| url-decode | Decode url |
| base64-encode | Base64 encode |
| base64-decode | Base64 decode |
| 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
34 changes: 34 additions & 0 deletions cmd/base64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"encoding/base64"
"fmt"

"github.com/spf13/cobra"
)

var base64EncodeCmd = &cobra.Command{
Use: "base64-encode [text]",
Short: "Base64 encode",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
s := base64.StdEncoding.EncodeToString([]byte(args[0]))
fmt.Println(s)
},
}

var base64DecodeCmd = &cobra.Command{
Use: "base64-decode [text]",
Short: "Base64 decode",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
b, err := base64.StdEncoding.DecodeString(args[0])
if err != nil {
fmt.Println("Invalid text!")
return
}
fmt.Println(string(b))
},
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func commands() []*cobra.Command {
md5Cmd,
urlEncodeCmd,
urlDecodeCmd,
base64EncodeCmd,
base64DecodeCmd,
randStringCmd,
countCmd,
CamelCaseCmd,
Expand Down

0 comments on commit 0e9d9ef

Please # to comment.