We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3d201d7 commit f7e197fCopy full SHA for f7e197f
archive/g/go/base64-encode-decode.go
@@ -0,0 +1,39 @@
1
+package main
2
+
3
+import (
4
+ "encoding/base64"
5
+ "fmt"
6
+ "os"
7
+)
8
9
+func die() {
10
+ fmt.Println("Usage: please provide a mode and a string to encode/decode")
11
+ os.Exit(1)
12
+}
13
14
+func main() {
15
+ if len(os.Args) < 3 {
16
+ die()
17
+ }
18
19
+ enc := base64.StdEncoding
20
21
+ if len(os.Args[2]) == 0 {
22
23
24
25
+ switch os.Args[1] {
26
+ case "encode":
27
+ fmt.Println(enc.EncodeToString([]byte(os.Args[2])))
28
+ return
29
+ case "decode":
30
+ s, err := enc.DecodeString(os.Args[2])
31
+ if err != nil {
32
33
34
35
+ fmt.Println(string(s))
36
+ default:
37
38
39
0 commit comments