summaryrefslogtreecommitdiff
path: root/exports
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
commitb1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch)
tree2133e4045b4af4d07a98674b7ae3a234670f0305 /exports
parent3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff)
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.
Diffstat (limited to 'exports')
-rw-r--r--exports/Makefile2
-rw-r--r--exports/exports.go22
2 files changed, 6 insertions, 18 deletions
diff --git a/exports/Makefile b/exports/Makefile
index 86dbec2..b833228 100644
--- a/exports/Makefile
+++ b/exports/Makefile
@@ -16,7 +16,7 @@ endif
# Build shared library and remove lib prefix (if any) from header name
# GOOS and GOARCH envvars are set by common.mk
# This extra target prevents unnecessary rebuild
-lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../src/*.go
+lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ..
CGO_ENABLED=1 go build -o $@ -buildmode=c-shared $<
mv lib/$(GOOS)/$(GOARCH)/$(LIB_PREFIX)$(LIB_NAME).h lib/$(GOOS)/$(GOARCH)/$(LIB_NAME).h || true # Normalize header name
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