File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed
Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,15 @@ devd convert to_upper_case [input]
110110# devd c uppercase aa
111111```
112112
113+ #### Encode/Decode base64
114+
115+ ``` bash
116+ devd convert encode_base64 [input]
117+ # devd c base64 123
118+ devd convert decode_base64 [base64]
119+ # devd c decode_base64 TVRJeg==
120+ ```
121+
113122### Hashing tools
114123
115124``` bash
Original file line number Diff line number Diff line change 1+ package convert
2+
3+ import (
4+ "encoding/base64"
5+ "fmt"
6+ libutils "github.com/EscanBE/go-lib/utils"
7+ "github.com/spf13/cobra"
8+ )
9+
10+ // GetDecodeBase64CaseCmd creates a helper command that decode base64
11+ func GetDecodeBase64CaseCmd () * cobra.Command {
12+ cmd := & cobra.Command {
13+ Use : "decode_base64 [base64]" ,
14+ Short : "Decode base64" ,
15+ Args : cobra .ExactArgs (1 ),
16+ Run : func (cmd * cobra.Command , args []string ) {
17+ data , err := base64 .StdEncoding .DecodeString (args [0 ])
18+ libutils .ExitIfErr (err , "failed to decode base64" )
19+
20+ fmt .Println (string (data ))
21+ },
22+ }
23+
24+ return cmd
25+ }
Original file line number Diff line number Diff line change 1+ package convert
2+
3+ import (
4+ "encoding/base64"
5+ "fmt"
6+ "github.com/spf13/cobra"
7+ "strings"
8+ )
9+
10+ // GetEncodeBase64CaseCmd creates a helper command that encode input into base64
11+ func GetEncodeBase64CaseCmd () * cobra.Command {
12+ cmd := & cobra.Command {
13+ Use : "encode_base64 [text]" ,
14+ Aliases : []string {"base64" },
15+ Short : "Encode input into base64" ,
16+ Args : cobra .MinimumNArgs (1 ),
17+ Run : func (cmd * cobra.Command , args []string ) {
18+ fmt .Println (base64 .StdEncoding .EncodeToString ([]byte (strings .Join (args , " " ))))
19+ },
20+ }
21+
22+ return cmd
23+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ func Commands() *cobra.Command {
1919 GetConvertSolcSignatureCmd (),
2020 GetConvertToLowerCaseCmd (),
2121 GetConvertToUpperCaseCmd (),
22+ GetDecodeBase64CaseCmd (),
23+ GetEncodeBase64CaseCmd (),
2224 )
2325
2426 return cmd
You can’t perform that action at this time.
0 commit comments