refactoring around the new sdk approach (#34)

This commit is contained in:
Michael Quigley 2023-07-10 13:44:58 -04:00
parent 29b87571cb
commit 917ba12ce6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 65 additions and 0 deletions

23
sdk/model.go Normal file
View File

@ -0,0 +1,23 @@
package sdk
type BackendMode string
const (
ProxyBackendMode BackendMode = "proxy"
WebBackendMode BackendMode = "web"
TcpTunnelBackendMode BackendMode = "tcpTunnel"
UdpTunnelBackendMode BackendMode = "udpTunnel"
)
type ShareMode string
const (
PrivateShareMode ShareMode = "private"
PublicShareMode ShareMode = "public"
)
type ShareRequest struct {
BackendMode BackendMode
ShareMode ShareMode
Target string
}

42
sdk/share.go Normal file
View File

@ -0,0 +1,42 @@
package sdk
import (
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/zrokdir"
"github.com/pkg/errors"
)
type Share struct {
Token string
}
func NewShare(request *ShareRequest) (*Share, error) {
switch request.ShareMode {
case PrivateShareMode:
return newPrivateShare(request)
case PublicShareMode:
return newPublicShare(request)
default:
return nil, errors.Errorf("unknown share mode '%v'", request.ShareMode)
}
}
func newPrivateShare(request *ShareRequest) (*Share, error) {
return nil, nil
}
func newPublicShare(request *ShareRequest) (*Share, error) {
return nil, nil
}
func loadEnvironment(request *ShareRequest) (*zrokdir.ZrokDir, error) {
zrd, err := zrokdir.Load()
if err != nil {
return nil, errors.Wrap(err, "error loading zrokdir")
}
return zrd, nil
}
func createShare(zrd *zrokdir.ZrokDir, req *rest_model_zrok.ShareRequest) (*Share, error) {
return nil, nil
}