-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_example_test.go
More file actions
53 lines (46 loc) · 1.78 KB
/
encode_example_test.go
File metadata and controls
53 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package core_test
import . "dappco.re/go"
// ExampleHexEncode encodes bytes as hex through `HexEncode` for token and payload
// encoding. Byte and string encoders return predictable wrapper values for tokens and
// payloads.
func ExampleHexEncode() {
Println(HexEncode([]byte("hello")))
// Output: 68656c6c6f
}
// ExampleHexDecode decodes hex text through `HexDecode` for token and payload encoding.
// Byte and string encoders return predictable wrapper values for tokens and payloads.
func ExampleHexDecode() {
r := HexDecode("68656c6c6f")
Println(string(r.Value.([]byte)))
// Output: hello
}
// ExampleBase64Encode encodes bytes as base64 through `Base64Encode` for token and payload
// encoding. Byte and string encoders return predictable wrapper values for tokens and
// payloads.
func ExampleBase64Encode() {
Println(Base64Encode([]byte("hello")))
// Output: aGVsbG8=
}
// ExampleBase64Decode decodes base64 text through `Base64Decode` for token and payload
// encoding. Byte and string encoders return predictable wrapper values for tokens and
// payloads.
func ExampleBase64Decode() {
r := Base64Decode("aGVsbG8=")
Println(string(r.Value.([]byte)))
// Output: hello
}
// ExampleBase64URLEncode encodes bytes for URL-safe base64 through `Base64URLEncode` for
// token and payload encoding. Byte and string encoders return predictable wrapper values
// for tokens and payloads.
func ExampleBase64URLEncode() {
Println(Base64URLEncode([]byte("hello?")))
// Output: aGVsbG8_
}
// ExampleBase64URLDecode decodes URL-safe base64 text through `Base64URLDecode` for token
// and payload encoding. Byte and string encoders return predictable wrapper values for
// tokens and payloads.
func ExampleBase64URLDecode() {
r := Base64URLDecode("aGVsbG8_")
Println(string(r.Value.([]byte)))
// Output: hello?
}