refactor(ax): align remaining AX docs and invalid-input errors
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
702286a583
commit
e1efd3634c
5 changed files with 22 additions and 6 deletions
5
io.go
5
io.go
|
|
@ -385,6 +385,9 @@ func (medium *MemoryMedium) WriteStream(path string) (goio.WriteCloser, error) {
|
|||
return medium.Create(path)
|
||||
}
|
||||
|
||||
// Example: medium := io.NewMemoryMedium()
|
||||
// Example: _ = medium.Write("config/app.yaml", "port: 8080")
|
||||
// Example: file, _ := medium.Open("config/app.yaml")
|
||||
type MemoryFile struct {
|
||||
name string
|
||||
content []byte
|
||||
|
|
@ -408,6 +411,8 @@ func (file *MemoryFile) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Example: medium := io.NewMemoryMedium()
|
||||
// Example: writer, _ := medium.Create("logs/app.log")
|
||||
type MemoryWriteCloser struct {
|
||||
medium *MemoryMedium
|
||||
path string
|
||||
|
|
|
|||
4
s3/s3.go
4
s3/s3.go
|
|
@ -90,10 +90,10 @@ func normalisePrefix(prefix string) string {
|
|||
// Example: _ = medium.Write("reports/daily.txt", "done")
|
||||
func New(options Options) (*Medium, error) {
|
||||
if options.Bucket == "" {
|
||||
return nil, core.E("s3.New", "bucket name is required", nil)
|
||||
return nil, core.E("s3.New", "bucket name is required", fs.ErrInvalid)
|
||||
}
|
||||
if options.Client == nil {
|
||||
return nil, core.E("s3.New", "client is required", nil)
|
||||
return nil, core.E("s3.New", "client is required", fs.ErrInvalid)
|
||||
}
|
||||
medium := &Medium{
|
||||
client: options.Client,
|
||||
|
|
|
|||
|
|
@ -23,12 +23,14 @@ var (
|
|||
NoKeyConfiguredError = core.E("sigil.NoKeyConfiguredError", "no encryption key configured", nil)
|
||||
)
|
||||
|
||||
// Example: obfuscator := &sigil.XORObfuscator{}
|
||||
type PreObfuscator interface {
|
||||
Obfuscate(data []byte, entropy []byte) []byte
|
||||
|
||||
Deobfuscate(data []byte, entropy []byte) []byte
|
||||
}
|
||||
|
||||
// Example: obfuscator := &sigil.XORObfuscator{}
|
||||
type XORObfuscator struct{}
|
||||
|
||||
func (obfuscator *XORObfuscator) Obfuscate(data []byte, entropy []byte) []byte {
|
||||
|
|
@ -76,6 +78,7 @@ func (obfuscator *XORObfuscator) deriveKeyStream(entropy []byte, length int) []b
|
|||
return stream
|
||||
}
|
||||
|
||||
// Example: obfuscator := &sigil.ShuffleMaskObfuscator{}
|
||||
type ShuffleMaskObfuscator struct{}
|
||||
|
||||
func (obfuscator *ShuffleMaskObfuscator) Obfuscate(data []byte, entropy []byte) []byte {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
goio "io"
|
||||
"io/fs"
|
||||
|
||||
core "dappco.re/go/core"
|
||||
"golang.org/x/crypto/blake2b"
|
||||
|
|
@ -20,6 +21,7 @@ import (
|
|||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
// Example: reverseSigil, _ := sigil.NewSigil("reverse")
|
||||
type ReverseSigil struct{}
|
||||
|
||||
func (sigil *ReverseSigil) In(data []byte) ([]byte, error) {
|
||||
|
|
@ -37,6 +39,7 @@ func (sigil *ReverseSigil) Out(data []byte) ([]byte, error) {
|
|||
return sigil.In(data)
|
||||
}
|
||||
|
||||
// Example: hexSigil, _ := sigil.NewSigil("hex")
|
||||
type HexSigil struct{}
|
||||
|
||||
func (sigil *HexSigil) In(data []byte) ([]byte, error) {
|
||||
|
|
@ -57,6 +60,7 @@ func (sigil *HexSigil) Out(data []byte) ([]byte, error) {
|
|||
return dst, err
|
||||
}
|
||||
|
||||
// Example: base64Sigil, _ := sigil.NewSigil("base64")
|
||||
type Base64Sigil struct{}
|
||||
|
||||
func (sigil *Base64Sigil) In(data []byte) ([]byte, error) {
|
||||
|
|
@ -77,6 +81,7 @@ func (sigil *Base64Sigil) Out(data []byte) ([]byte, error) {
|
|||
return dst[:n], err
|
||||
}
|
||||
|
||||
// Example: gzipSigil, _ := sigil.NewSigil("gzip")
|
||||
type GzipSigil struct {
|
||||
outputWriter goio.Writer
|
||||
}
|
||||
|
|
@ -116,6 +121,7 @@ func (sigil *GzipSigil) Out(data []byte) ([]byte, error) {
|
|||
return out, nil
|
||||
}
|
||||
|
||||
// Example: jsonSigil := &sigil.JSONSigil{Indent: true}
|
||||
type JSONSigil struct{ Indent bool }
|
||||
|
||||
func (sigil *JSONSigil) In(data []byte) ([]byte, error) {
|
||||
|
|
@ -129,7 +135,7 @@ func (sigil *JSONSigil) In(data []byte) ([]byte, error) {
|
|||
if err, ok := result.Value.(error); ok {
|
||||
return nil, core.E("sigil.JSONSigil.In", "decode json", err)
|
||||
}
|
||||
return nil, core.E("sigil.JSONSigil.In", "decode json", nil)
|
||||
return nil, core.E("sigil.JSONSigil.In", "decode json", fs.ErrInvalid)
|
||||
}
|
||||
|
||||
compact := core.JSONMarshalString(decoded)
|
||||
|
|
@ -143,6 +149,7 @@ func (sigil *JSONSigil) Out(data []byte) ([]byte, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
// Example: hashSigil := sigil.NewHashSigil(crypto.SHA256)
|
||||
type HashSigil struct {
|
||||
Hash crypto.Hash
|
||||
}
|
||||
|
|
@ -193,7 +200,7 @@ func (sigil *HashSigil) In(data []byte) ([]byte, error) {
|
|||
case crypto.BLAKE2b_512:
|
||||
hasher, _ = blake2b.New512(nil)
|
||||
default:
|
||||
return nil, core.E("sigil.HashSigil.In", "hash algorithm not available", nil)
|
||||
return nil, core.E("sigil.HashSigil.In", "hash algorithm not available", fs.ErrInvalid)
|
||||
}
|
||||
|
||||
hasher.Write(data)
|
||||
|
|
@ -258,7 +265,7 @@ func NewSigil(name string) (Sigil, error) {
|
|||
case "blake2b-512":
|
||||
return NewHashSigil(crypto.BLAKE2b_512), nil
|
||||
default:
|
||||
return nil, core.E("sigil.NewSigil", core.Concat("unknown sigil name: ", name), nil)
|
||||
return nil, core.E("sigil.NewSigil", core.Concat("unknown sigil name: ", name), fs.ErrInvalid)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ type Medium struct {
|
|||
|
||||
var _ coreio.Medium = (*Medium)(nil)
|
||||
|
||||
// Example: medium, _ := sqlite.New(sqlite.Options{Path: ":memory:", Table: "files"})
|
||||
type Options struct {
|
||||
Path string
|
||||
Table string
|
||||
|
|
@ -41,7 +42,7 @@ func normaliseTableName(table string) string {
|
|||
// Example: _ = medium.Write("config/app.yaml", "port: 8080")
|
||||
func New(options Options) (*Medium, error) {
|
||||
if options.Path == "" {
|
||||
return nil, core.E("sqlite.New", "database path is required", nil)
|
||||
return nil, core.E("sqlite.New", "database path is required", fs.ErrInvalid)
|
||||
}
|
||||
|
||||
medium := &Medium{table: normaliseTableName(options.Table)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue