photoprism-client-go/examples/common.go

31 lines
591 B
Go

package main
import (
"fmt"
"os"
photoprism "github.com/astravexton/photoprism-client-go"
"github.com/astravexton/logger"
)
// format string, a ...interface{}
func halt(code int, msg string, a ...interface{}) {
str := fmt.Sprintf(msg, a...)
logger.Critical(str)
os.Exit(code)
}
func auth() photoprism.ClientAuthenticator {
user := os.Getenv("PHOTOPRISM_USER")
if user == "" {
halt(1, "Missing PHOTOPRISM_USER")
}
pass := os.Getenv("PHOTOPRISM_PASS")
if pass == "" {
halt(2, "Missing PHOTOPRISM_PASS")
}
auth := photoprism.NewClientAuthLogin(user, pass)
return auth
}