ajson
ajson copied to clipboard
Add new functions `b64encode` and `b4decode`
Add new functions b64encode
and b64decode
that are equal to the same functions from encoding/base64
Select the name for method:
-
b64encode
-
base64_encode
-
encode_base64
-
encodeB64
-
b64_encode
- etc.
Hi @spyzhov can I work on this issue? I am fairly new to Golang, so it could take some time.
@ryzheboka, sure! Please create 2 new methods with names base64_encode
and base64_decode
.
You can implement them in the same way as function avg
(source: https://github.com/spyzhov/ajson/blob/master/math.go#L363-L380).
Input and Output type should be String
only.
Please cover them with tests in the math_test.go
file.
Do I declare the methods using the following signatures?
"base64_encode": func(node *Node) (result *Node, err error) { ... }
"base64_decode": func(node *Node) (result *Node, err error) { ... }
where the each Node is a string Node? What do I do if the Node isn't a string? Or should I rather use the following signature?
"base64_encode": func(input string) (result string, err error) { ... }
The first suggestion was right, it should be something like this:
"base64_encode": func(node *Node) (result *Node, err error) {
if node.IsString() {
if res, err := node.GetString(); err != nil {
return nil, err
} else {
var result string
// ... implementation
return valueNode(nil, "base64_encode", String, result), nil
}
}
return valueNode(nil, "base64_encode", Null, nil), nil
},
"base64_decode": func(node *Node) (result *Node, err error) {
The current implementation of functions could have only 1 argument and it's applicable to any type of node.
Also, please be aware that base64
can be configured with/without padding:
_, _ = base64.StdEncoding.WithPadding(base64.NoPadding).DecodeString(str)
_, _ = base64.StdEncoding.WithPadding(base64.StdPadding).DecodeString(str)
Some strings can not be decoded with/without padding.
Probably better to create 4 functions: pair of functions with and without StdPadding(=)
There seems to be a problem with https://github.com/mattn/goveralls which leads to the pipeline failure, The pipeline cannot execute go get github.com/mattn/goveralls
. Here is the problem: https://app.travis-ci.com/github/spyzhov/ajson/jobs/587506014. Is it related to my PR, or is it a different problem?
It's OK, when I'll press a button to run it "from my name", it will resolve this problem.