Pushing changes for testing harness before my next meeting. Adding working exec library and sample code
Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
parent
95794522e0
commit
b107d98a37
14 changed files with 313 additions and 19 deletions
20
examples/app_upload_download_photo.go
Normal file
20
examples/app_upload_download_photo.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
sampleapp "github.com/kris-nova/client-go/sample-app"
|
||||
"github.com/kris-nova/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger.Level = 4
|
||||
app := sampleapp.New()
|
||||
var err error
|
||||
err = app.Start()
|
||||
if err != nil {
|
||||
logger.Critical(err.Error())
|
||||
}
|
||||
err = app.Stop()
|
||||
if err != nil {
|
||||
logger.Critical(err.Error())
|
||||
}
|
||||
}
|
30
examples/common.go
Normal file
30
examples/common.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
photoprism "github.com/kris-nova/client-go"
|
||||
|
||||
"github.com/kris-nova/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
|
||||
}
|
|
@ -5,29 +5,15 @@ import (
|
|||
"os"
|
||||
|
||||
photoprism "github.com/kris-nova/client-go"
|
||||
|
||||
"github.com/kris-nova/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 main() {
|
||||
user := os.Getenv("PHOTOPRISM_USER")
|
||||
if user == "" {
|
||||
halt(1, "Missing PHOTOPRISM_USER")
|
||||
uuid := os.Getenv("PHOTOPRISM_ID")
|
||||
if uuid == "" {
|
||||
halt(2, "Missing PHOTOPRISM_UUID")
|
||||
}
|
||||
pass := os.Getenv("PHOTOPRISM_PASS")
|
||||
if pass == "" {
|
||||
halt(2, "Missing PHOTOPRISM_PASS")
|
||||
}
|
||||
login := photoprism.NewClientAuthLogin("username", "password")
|
||||
photoclient := photoprism.New(login)
|
||||
photo, err := photoclient.V1().GetPhoto("123")
|
||||
client := photoprism.New(auth())
|
||||
photo, err := client.V1().GetPhoto(uuid)
|
||||
if err != nil {
|
||||
halt(3, "Error fetching photo: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue