From 91d8e97178854785c9ef65859e3d050656bdff00 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Tue, 5 Sep 2023 16:56:00 -0400 Subject: [PATCH] Add generated code --- x/examples/mobileproxy/README.md | 157 ++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 3 deletions(-) diff --git a/x/examples/mobileproxy/README.md b/x/examples/mobileproxy/README.md index 29e102bd..f0fdbc01 100644 --- a/x/examples/mobileproxy/README.md +++ b/x/examples/mobileproxy/README.md @@ -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 @@ -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: +
+iOS generated Code + +`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 { +} +@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 +``` + +
+ +
+ Android generated Code + +`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(); + } +} +``` + +
+ +### Clean up ```bash rm -rf ./out/