-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 978f1e4
Showing
20 changed files
with
777 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = tab | ||
tab_width = 8 | ||
max_line_length = 2048 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# macOS | ||
.DS_Store | ||
!**/.metadata_never_index | ||
|
||
# Xcode/Swift | ||
!default.mode1v3 | ||
!default.mode2v3 | ||
!default.pbxuser | ||
!default.perspectivev3 | ||
.build/ | ||
.swiftpm | ||
*.app | ||
*.dSYM.zip | ||
*.hmap | ||
*.ipa | ||
*.mode1v3 | ||
*.mode2v3 | ||
*.moved-aside | ||
*.pbxuser | ||
*.perspectivev3 | ||
*.xccheckout | ||
*.xcframework | ||
*.xcuserstate | ||
DerivedData | ||
xcuserdata | ||
|
||
# Vendor dirs | ||
**/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
useTabs: true | ||
tabWidth: 8 | ||
semi: false | ||
singleQuote: true | ||
printWidth: 80 | ||
trailingComma: "es5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--indent tab | ||
--exclude **/.build | ||
--exclude **/.git | ||
--exclude **/.github | ||
--exclude **/.swiftpm | ||
--exclude **/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// List of extensions which should be recommended for users of this workspace. | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
"recommendations": [ | ||
"davidanson.vscode-markdownlint", | ||
"eamodio.gitlens", | ||
"foxundermoon.shell-format", | ||
"golang.go", | ||
"mariomatheu.syntax-project-pbxproj", | ||
"redhat.vscode-yaml", | ||
"stkb.rewrap", | ||
"vknabel.vscode-swiftformat", | ||
"xaver.clang-format" | ||
], | ||
|
||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace. | ||
"unwantedRecommendations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
// Editor | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"editor.detectIndentation": false, | ||
"editor.formatOnSave": true, | ||
"editor.insertSpaces": false, | ||
"editor.tabSize": 8, | ||
"files.eol": "\n", | ||
|
||
// Files | ||
"files.exclude": { | ||
"**/.build": true, | ||
"**/.git": true, | ||
"**/build": true, | ||
"**/vendor": true | ||
}, | ||
"files.associations": {}, | ||
"files.insertFinalNewline": true, | ||
"files.watcherExclude": { | ||
"**/.git/objects/**": true, | ||
"**/.git/subtree-cache/**": true | ||
}, | ||
"files.trimTrailingWhitespace": true, | ||
|
||
// Go | ||
"[go]": { | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": true | ||
} | ||
}, | ||
"[go.mod]": { | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": true, | ||
"source.organizeImports": true | ||
} | ||
}, | ||
"go.useLanguageServer": true, | ||
"gopls": { | ||
"usePlaceholders": true | ||
}, | ||
|
||
// HTML | ||
"html.format.contentUnformatted": "pre,code,textarea,script", | ||
"html.format.unformatted": "pre,code,textarea,script,wbr", | ||
"html.format.endWithNewline": true, | ||
|
||
// JSON | ||
"[json]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[jsonc]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
|
||
// Make | ||
"[makefile]": { | ||
"editor.tabSize": 8 | ||
}, | ||
|
||
// Markdown | ||
"[markdown]": { | ||
"editor.rulers": [80], | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.markdownlint": true | ||
} | ||
}, | ||
"markdown.preview.breaks": true, | ||
"markdownlint.config": { | ||
"default": true, | ||
"MD022": false, | ||
"MD024": false, | ||
"MD032": false | ||
}, | ||
|
||
// Property Lists | ||
"[plist]": { | ||
"editor.formatOnSave": true, | ||
"editor.tabSize": 8 | ||
}, | ||
|
||
// Shell | ||
"[shellscript]": { | ||
"editor.defaultFormatter": "foxundermoon.shell-format" | ||
}, | ||
|
||
// Swift | ||
"[swift]": { | ||
"editor.detectIndentation": false, | ||
"editor.insertSpaces": false, | ||
"editor.tabSize": 8 | ||
}, | ||
|
||
// YAML | ||
"[yaml]": { | ||
"editor.autoIndent": "keep", | ||
"editor.detectIndentation": true, | ||
"editor.insertSpaces": true, | ||
"editor.tabSize": 2, | ||
"editor.quickSuggestions": { | ||
"other": true, | ||
"comments": false, | ||
"strings": true | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.DEFAULT: build | ||
|
||
build: tools Frameworks $(wildcard Package.*) $(wildcard Sources/*/*) | ||
swift build --jobs 10 -c release | ||
|
||
.PHONY: tools | ||
tools: | ||
go generate -tags=tools ./internal/tools | ||
|
||
.PHONY: Frameworks | ||
Frameworks: Frameworks/EchoGo.xcframework | ||
|
||
Frameworks/%.xcframework: Makefile $(wildcard Sources/*/*.go) | ||
gomobile init | ||
gomobile bind -target ios -o $@ ./Sources/$* | ||
touch $@ | ||
|
||
test: build | ||
go test ./... | ||
swift test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "EchoKit", | ||
platforms: [ | ||
.macOS(.v11), | ||
.iOS(.v13), | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "EchoKit", | ||
targets: ["EchoGo"] | ||
), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "EchoKit" | ||
), | ||
.binaryTarget( | ||
name: "EchoGo", | ||
path: "Frameworks/EchoGo.xcframework" | ||
), | ||
.testTarget( | ||
name: "EchoKitTests", | ||
dependencies: ["EchoKit", "EchoGo"] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# QUIC + Go + gomobile | ||
|
||
Example Go package built into an XCFramework suitable for inclusion in an iOS or macOS app via Swift Package Manager. | ||
|
||
Depends on <https://golang.org/cl/310949>. | ||
|
||
## Author | ||
|
||
© Alta Software, LLC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Go | ||
|
||
import ( | ||
"github.com/alta/quic-go-mobile-example/internal/echo" | ||
) | ||
|
||
// Echo sends msg to addr via a QUIC datagram. | ||
// It returns the value of the first datagram received from the remote host or an error. | ||
// For testing purposes, this function explicitly skips TLS cert verification. | ||
// Do not use this in production. | ||
func Echo(addr, msg string) (string, error) { | ||
return echo.RoundTrip(addr, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Stub file so SPM doesn’t complain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import XCTest | ||
|
||
@testable import EchoGo | ||
|
||
class EchoTests: XCTestCase { | ||
static let host = "localhost" | ||
static let port = Int.random(in: 1025 ..< Int(Int16.max)) | ||
static let server = Process() | ||
|
||
override class func setUp() { | ||
super.setUp() | ||
|
||
let directory = URL(fileURLWithPath: #filePath) | ||
.deletingLastPathComponent() // EchoKitTests | ||
.deletingLastPathComponent() // Tests | ||
.deletingLastPathComponent() // Repo root | ||
|
||
server.currentDirectoryURL = directory | ||
server.executableURL = URL(fileURLWithPath: "/bin/sh") | ||
server.arguments = ["-c", "go run ./cmd/server -a \(host):\(port)"] | ||
server.environment = ProcessInfo.processInfo.environment | ||
|
||
do { | ||
try server.run() | ||
} catch { | ||
XCTFail("Failed to start test QUIC server.") | ||
} | ||
|
||
// Give the server a chance to start up | ||
sleep(4) | ||
} | ||
|
||
override class func tearDown() { | ||
server.terminate() | ||
super.tearDown() | ||
} | ||
|
||
func testEcho() throws { | ||
let addr = "\(Self.host):\(Self.port)" | ||
let message = "Hello QUIC!" | ||
var error: NSErrorPointer = nil | ||
|
||
let response = GoEcho(addr, message, error) | ||
|
||
XCTAssertEqual(response, message) | ||
XCTAssertEqual(error, nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
"github.com/alta/quic-go-mobile-example/internal/echo" | ||
) | ||
|
||
func main() { | ||
addr := flag.String("a", "localhost:4242", "address in host:port format") | ||
flag.Parse() | ||
msg := flag.Arg(0) | ||
if msg == "" { | ||
msg = "hello" | ||
} | ||
_, err := echo.RoundTrip(*addr, msg) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
"github.com/alta/quic-go-mobile-example/internal/echo" | ||
) | ||
|
||
func main() { | ||
addr := flag.String("a", "localhost:4242", "address in host:port format") | ||
flag.Parse() | ||
err := echo.Serve(*addr) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module github.com/alta/quic-go-mobile-example | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/alta/insecure v0.0.0-20210629202216-eec10269b9f1 | ||
github.com/lucas-clemente/quic-go v0.21.1 | ||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect | ||
golang.org/x/mobile v0.0.0-20210220033013-bdb1ca9a1e08 | ||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect | ||
golang.org/x/text v0.3.5 // indirect | ||
) | ||
|
||
replace golang.org/x/mobile => github.com/ydnar/gomobile v0.0.0-20210709044546-50f941d1f5dd |
Oops, something went wrong.