Skip to content
Snippets Groups Projects
app.go 957 B
Newer Older
  • Learn to ignore specific revisions
  • package api
    
    import (
    	"context"
    	"time"
    
    	apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/app"
    	nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client"
    )
    
    // Register checks if the app already exists and if not creates a new one.
    func Register(ctx context.Context, addr, appname, token string) (*apb.AppRegisterResponse, error) {
    	appClient, err := nbi.AppClient(addr, dialOptions...)
    	if err != nil {
    		return nil, err
    	}
    
    	req := &apb.AppRegisterRequest{
    		Timestamp: time.Now().UnixNano(),
    		Appname:   appname,
    		Token:     token,
    	}
    
    	return appClient.Register(ctx, req)
    }
    
    // Deregister deregisters an app.
    func Deregister(ctx context.Context, addr, appname, token string) (*apb.AppDeregisterResponse, error) {
    	appClient, err := nbi.AppClient(addr, dialOptions...)
    	if err != nil {
    		return nil, err
    	}
    
    	req := &apb.AppDeregisterRequest{
    		Timestamp: time.Now().UnixNano(),
    		Appname:   appname,
    	}
    
    	return appClient.Deregister(ctx, req)
    }