I'm an experienced programmer, but new to go, so apologies in advance for what I'm sure is an easy question.
The base64 example code on the goland.org
site includes the following code.
package main
import (
"encoding/base64"
"fmt"
)
func main() {
msg := "Hello, 世界"
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
fmt.Println(encoded)
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
fmt.Println("decode error:", err)
return
}
fmt.Println(string(decoded))
}
I can copy and use this code without issue, but as a new go programmer, I don't understand what that StdEncoding
part of the following lines does
decoded, err := base64.StdEncoding.DecodeString(encoded)
I understand the above program imports the encode/base64
functions into my program. However, if I look at the documentation, the base64 package consists of the following types and functions
func NewDecoder(enc *Encoding, r io.Reader) io.Reader
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
type CorruptInputError
func (e CorruptInputError) Error() string
type Encoding
func NewEncoding(encoder string) *Encoding
func (enc *Encoding) Decode(dst, src []byte) (n int, err error)
func (enc *Encoding) DecodeString(s string) ([]byte, error)
func (enc *Encoding) DecodedLen(n int) int
func (enc *Encoding) Encode(dst, src []byte)
func (enc *Encoding) EncodeToString(src []byte) string
func (enc *Encoding) EncodedLen(n int) int
func (enc Encoding) WithPadding(padding rune) *Encoding
I would expect to see a type of StdEncoding
-- but I don't see any mention of a StdEncoding
in this list.
So, my immediate question is -- what is StdEncoding
?
My higher level question is probably -- what, exactly, is exported from a module for consumption by a user of that module, and how can I, as a go user, browse those exported things.
Bonus points if you can correct any unwitting misuse of terms like module, export, import above and put them into a go context.