parent
9aa9c9c4c2
commit
a35ac4f2d3
@ -0,0 +1,4 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
type OperaSystem struct {
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
var operaSystem OperaSystem
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (fl *OperaSystem) ByteToBase64(b []byte) string {
|
||||||
|
return base64.StdEncoding.EncodeToString(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base64ToByte base64 string to byte
|
||||||
|
// baseStr parameter is base64 string
|
||||||
|
func (fl *OperaSystem) Base64ToByte(baseStr string) ([]byte, error) {
|
||||||
|
return base64.StdEncoding.DecodeString(string(baseStr))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByteToFile The byte array is converted into a file and landed
|
||||||
|
// The parameter b is the bate array filePath file path
|
||||||
|
func (fl *OperaSystem) ByteToFile(b []byte, filePath string) error {
|
||||||
|
//Open file Create a file if there is no file
|
||||||
|
file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = file.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func(file *os.File) {
|
||||||
|
err := file.Close()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}(file)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFile_ByteToBase64(t *testing.T) {
|
||||||
|
byteStr := []byte("hello world!")
|
||||||
|
base64Str := operaSystem.ByteToBase64(byteStr)
|
||||||
|
byteResult, _ := operaSystem.Base64ToByte(base64Str)
|
||||||
|
fmt.Println(base64Str)
|
||||||
|
fmt.Println(byteResult)
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
|
func (os *OperaSystem) GOOS() string {
|
||||||
|
return runtime.GOOS
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *OperaSystem) GOARCH() string {
|
||||||
|
return runtime.GOARCH
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *OperaSystem) GOGC() string {
|
||||||
|
return runtime.Compiler
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package operaSystem
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOS_GOOS(t *testing.T) {
|
||||||
|
fmt.Println(operaSystem.GOOS())
|
||||||
|
fmt.Println(operaSystem.GOGC())
|
||||||
|
}
|
||||||
Loading…
Reference in new issue