ncddns/mod/mod.go

52 lines
712 B
Go

package mod
import (
"encoding/json"
"flag"
"fmt"
"io"
)
var (
Verbose bool
)
func init() {
flag.BoolVar(&Verbose, "v", false, "verbose")
}
type IPSetRequest struct {
IP string
Domain string
Password string
Host string
}
func MustJSON(v any) []byte {
bytes, err := json.Marshal(v)
if err != nil {
panic(err)
}
return bytes
}
func TryBody(body io.Reader) string {
content, err := io.ReadAll(body)
if err != nil {
return fmt.Sprintf("failed reading body: %s", err.Error())
}
return string(content)
}
func Verboseln(args ...any) {
if Verbose {
fmt.Println(args...)
}
}
func Verbosefln(format string, args ...any) {
if Verbose {
fmt.Printf(format+"\n", args...)
}
}