From b1d92b395322f2164ccfb44b0f7caebbaece6b62 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Fri, 22 Apr 2022 16:29:59 +0200 Subject: Refactor: Restructure project - Add an internal folder where all the internal code lives - Make a state.go and state_test.go for the public interface This gives a more clear separation between functions and modules. It also makes this a more typical Go project setup. --- exports/exports.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'exports/exports.go') diff --git a/exports/exports.go b/exports/exports.go index 84cd571..aa6f5b6 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -14,7 +14,7 @@ void call_callback(PythonCB callback, const char* oldstate, const char* newstate */ import "C" import "unsafe" -import "github.com/jwijenbergh/eduvpn-common/src" +import "github.com/jwijenbergh/eduvpn-common" var P_StateCallback C.PythonCB @@ -63,7 +63,7 @@ func Connect(url *C.char) (*C.char, *C.char) { //export GetOrganizationsList func GetOrganizationsList() (*C.char, *C.char) { state := eduvpn.GetVPNState() - organizations, organizationsErr := state.GetOrganizationsList() + organizations, organizationsErr := state.GetDiscoOrganizations() return C.CString(organizations), C.CString(ErrorToString(organizationsErr)) } @@ -71,27 +71,15 @@ func GetOrganizationsList() (*C.char, *C.char) { //export GetServersList func GetServersList() (*C.char, *C.char) { state := eduvpn.GetVPNState() - servers, serversErr := state.GetServersList() + servers, serversErr := state.GetDiscoServers() return C.CString(servers), C.CString(ErrorToString(serversErr)) } //export SetProfileID func SetProfileID(data *C.char) *C.char { state := eduvpn.GetVPNState() - - if !state.InState(eduvpn.ASK_PROFILE) { - return C.CString("Invalid state for setting a profile") - } - - // Set current profile to id - profile_id := C.GoString(data) - - server, serverErr := state.Servers.GetCurrentServer() - if serverErr != nil { - return C.CString("No server found for setting a profile ID") - } - server.Profiles.Current = profile_id - return C.CString("") + profileErr := state.SetProfileID(C.GoString(data)) + return C.CString(ErrorToString(profileErr)) } //export FreeString -- cgit v1.2.3