Skip to content

Commit

Permalink
Add generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Sep 5, 2023
1 parent e998ff7 commit 91d8e97
Showing 1 changed file with 154 additions and 3 deletions.
157 changes: 154 additions & 3 deletions x/examples/mobileproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

This package illustrates the use Go Mobile to generarate a mobile library to run a local proxy and configure your app networking libraries.

1. Build the Go Mobile binaries with [`go build`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)
### Build the Go Mobile binaries with [`go build`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies)

```bash
go build -o ./out/ golang.org/x/mobile/cmd/gomobile golang.org/x/mobile/cmd/gobind
```

2. Build the iOS and Android libraries with [`gomobile bind`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS)
### Build the iOS and Android libraries with [`gomobile bind`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS)

```bash
PATH="$PATH:$(pwd)/out" $(pwd)/out/gomobile bind -target=ios -o "$(pwd)/out/LocalProxy.xcframework" github.com/Jigsaw-Code/outline-sdk/x/appproxy
Expand All @@ -17,7 +17,158 @@ PATH="$PATH:$(pwd)/out" $(pwd)/out/gomobile bind -target=android -o "$(pwd)/out/

Note: Gomobile expects gobind to be in the PATH, that's why we need to prebuild it, and set up the PATH accordingly.

3. To clean up:
<details>
<summary>iOS generated Code</summary>

`Appproxy.objc.h`:

```objc
// Objective-C API for talking to github.com/Jigsaw-Code/outline-sdk/x/appproxy Go package.
// gobind -lang=objc github.com/Jigsaw-Code/outline-sdk/x/appproxy
//
// File is generated by gobind. Do not edit.

#ifndef __Appproxy_H__
#define __Appproxy_H__

@import Foundation;
#include "ref.h"
#include "Universe.objc.h"


@class AppproxyProxy;

/**
* Proxy enables you to get the actual address bound by the server and stop the service when no longer needed.
*/
@interface AppproxyProxy : NSObject <goSeqRefInterface> {
}
@property(strong, readonly) _Nonnull id _ref;

- (nonnull instancetype)initWithRef:(_Nonnull id)ref;
- (nonnull instancetype)init;
/**
* Address returns the actual IP and port the server is bound to.
*/
- (NSString* _Nonnull)address;
/**
* Stops gracefully stops the proxy service, waiting for at most timeout seconds before forcefully closing it.
*/
- (void)stop:(long)timeoutSeconds;
@end

/**
* RunProxy runs a local web proxy that listens on localAddress, and uses the transportConfig to
create the [transport.StreamDialer] to use to connect to the destination from the proxy requests.
*/
FOUNDATION_EXPORT AppproxyProxy* _Nullable AppproxyRunProxy(NSString* _Nullable localAddress, NSString* _Nullable transportConfig, NSError* _Nullable* _Nullable error);

#endif
```

</details>

<details>
<summary>Android generated Code</summary>

`Appproxy.java`:

```java
// Code generated by gobind. DO NOT EDIT.

// Java class appproxy.Appproxy is a proxy for talking to a Go program.
//
// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/appproxy
package appproxy;

import go.Seq;

public abstract class Appproxy {
static {
Seq.touch(); // for loading the native library
_init();
}

private Appproxy() {} // uninstantiable

// touch is called from other bound packages to initialize this package
public static void touch() {}

private static native void _init();



/**
* RunProxy runs a local web proxy that listens on localAddress, and uses the transportConfig to
create the [transport.StreamDialer] to use to connect to the destination from the proxy requests.
*/
public static native Proxy runProxy(String localAddress, String transportConfig) throws Exception;
}

```

`Proxy.java`:

```java
// Code generated by gobind. DO NOT EDIT.

// Java class appproxy.Proxy is a proxy for talking to a Go program.
//
// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/appproxy
package appproxy;

import go.Seq;

/**
* Proxy enables you to get the actual address bound by the server and stop the service when no longer needed.
*/
public final class Proxy implements Seq.Proxy {
static { Appproxy.touch(); }

private final int refnum;

@Override public final int incRefnum() {
Seq.incGoRef(refnum, this);
return refnum;
}

Proxy(int refnum) { this.refnum = refnum; Seq.trackGoRef(refnum, this); }

public Proxy() { this.refnum = __New(); Seq.trackGoRef(refnum, this); }

private static native int __New();

/**
* Address returns the actual IP and port the server is bound to.
*/
public native String address();
/**
* Stops gracefully stops the proxy service, waiting for at most timeout seconds before forcefully closing it.
*/
public native void stop(long timeoutSeconds);
@Override public boolean equals(Object o) {
if (o == null || !(o instanceof Proxy)) {
return false;
}
Proxy that = (Proxy)o;
return true;
}

@Override public int hashCode() {
return java.util.Arrays.hashCode(new Object[] {});
}

@Override public String toString() {
StringBuilder b = new StringBuilder();
b.append("Proxy").append("{");
return b.append("}").toString();
}
}
```

</details>

### Clean up

```bash
rm -rf ./out/
Expand Down

0 comments on commit 91d8e97

Please sign in to comment.