summaryrefslogtreecommitdiff
path: root/docs/src/api/go
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/api/go')
-rw-r--r--docs/src/api/go/README.md9
-rw-r--r--docs/src/api/go/example.md63
-rw-r--r--docs/src/api/go/functions.md61
3 files changed, 133 insertions, 0 deletions
diff --git a/docs/src/api/go/README.md b/docs/src/api/go/README.md
index 452b575..6106f1e 100644
--- a/docs/src/api/go/README.md
+++ b/docs/src/api/go/README.md
@@ -1 +1,10 @@
# Go
+The API that has no additional wrapper code is the Go API. To begin to use the Go library in a Go client you first need to import it:
+
+```go
+import "github.com/jwijenbergh/eduvpn-common"
+```
+
+This brings the library into scope using the eduvpn-common prefix.
+
+The functions that we define all operate on a `VPNState` object, thus to call a function it needs to be first created and then the function needs to be called. An example of how to tie all of this together is done at the end.
diff --git a/docs/src/api/go/example.md b/docs/src/api/go/example.md
new file mode 100644
index 0000000..e7b0d36
--- /dev/null
+++ b/docs/src/api/go/example.md
@@ -0,0 +1,63 @@
+# Example with Comments
+
+```go
+
+// Bring the library into scope with the eduvpn prefix
+import eduvpn "github.com/jwijenbergh/eduvpn-common"
+
+// Callbacks
+
+func stateCallback(state *eduvpn.VPNState, oldState string, newState string, data string) {
+
+ // OAuth is started, open the browser with the authorization URL
+ if newState == "OAuth_Started" {
+ openBrowser(data)
+ }
+
+ // Multiple profiles are found, we need to send a profile ID back using state.SetProfileID
+ if newState == "Ask_Profile" {
+ selectAndSendProfile(state, data)
+ }
+}
+
+func main() {
+ // Create the VPNState
+ state := &eduvpn.VPNState{}
+
+ // Register the state
+ // We use linux so the client ID will be org.eduvpn.app.linux
+ // We want to store the config files in configs
+ // We wrap the callback with the state argument
+ // And enable debugging
+ registerErr := state.Register("org.eduvpn.app.linux", "configs", func(old string, new string, data string) {
+ stateCallback(state, old, new, data)
+ }, true)
+
+ if registErr != nil {
+ // handle the error of not being able to register
+ }
+
+ // Cleanup the library at the end
+ defer state.Deregister()
+
+ // Connect to an example server without forcing TCP
+ config, configType, configErr := state.GetConnectConfig("eduvpn.example.com", false)
+
+ if configErr != nil {
+ // handle the error of not being able to get a config
+ }
+
+ if configType == "wireguard" {
+ // Connect using wireguard with the config
+ } else {
+ // Connect using OpenVPN with the config
+ }
+
+ // We are connected
+ setConnectErr := state.SetConnected()
+
+ if setConnectErr != nil {
+ // handle the error of not being able to call set connected
+ }
+}
+```
diff --git a/docs/src/api/go/functions.md b/docs/src/api/go/functions.md
index 0c5faf5..c647787 100644
--- a/docs/src/api/go/functions.md
+++ b/docs/src/api/go/functions.md
@@ -1 +1,62 @@
# Functions
+## Registering
+See [Overview](../overview/registering.html)
+```go
+func Register(name string, directory string, stateCallback func, debug bool) error
+```
+- `name`: The name of the client
+- `directory`: The directory where the configs and logging should be stored
+- `stateCallback`: function with three arguments, full type:
+ ```go
+ func(oldState string, newState string, data string)
+ ```
+- `debug`: Whether or not we want to enable debugging
+
+Returns an `error` type, nil if no error
+
+## Discovery
+See [Overview](../overview/discovery.html)
+```go
+func GetDiscoServers() (string, error)
+func GetDiscoOrganizations() (string, error)
+```
+
+Returns a string of JSON data with the servers/organizations and an `error`, nil if no error
+
+## OpenVPN/Wireguard config
+See [Overview](../overview/getconfig.html)
+```go
+func GetConnectConfig(url string, forceTCP bool) (string, string, error)
+```
+- `url`: The url of the server to get a connect config for
+- `forceTCP`: Whether or not we want to force enable TCP
+
+Returns:
+- A `string` of the OpenVPN/Wireguard config
+- A `string`, `openvpn` or `wireguard` indicating if it is an OpenVPN or Wireguard config
+- An `error` (can be nil)
+
+### Setting a profile ID
+```go
+func SetProfileID(profileID string) error
+```
+- `profileID`: The profile ID to connect to
+
+Returns an `error`, can be nil indicating no error
+
+## Connecting/Disconnecting
+See [Overview](../overview/connecting.html)
+```go
+func SetConnected() error
+func SetDisconnected() error
+```
+
+Returns an `error`, can be nil indicating no error
+
+## Deregister
+See [Overview](../overview/deregistering.html)
+```go
+func Deregister() error
+```
+
+Returns an `error`, can be nil indicating no error