1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Foundation
import AtircGo
/// Swift-facing wrapper around the embedded Go library.
enum GoBridge {
static var runtimeVersion: String { AtircgoVersion() }
static func echo(_ name: String) -> String {
AtircgoEcho(name)
}
static func sha256Hex(_ data: Data) -> String {
AtircgoSHA256Hex(data)
}
static func parseCommand(_ line: String) throws -> String {
var error: NSError?
let command = AtircgoParseCommand(line, &error)
if let error {
throw error
}
return command
}
static func makeCounter() -> AtircgoCounter? {
AtircgoNewCounter()
}
static func recordAfter(_ message: String) {
AtircgoRecordAfter(message)
}
static func lastRecorded() -> String {
AtircgoLastRecorded()
}
static func emitLater(_ callback: AtircgoCallbackProtocol, message: String) {
AtircgoEmitLater(callback, message)
}
}
/// Bridges Go callback invocations to a Swift closure.
nonisolated final class GoCallback: NSObject, AtircgoCallbackProtocol, @unchecked Sendable {
private let handler: @Sendable (String?) -> Void
init(handler: @escaping @Sendable (String?) -> Void) {
self.handler = handler
super.init()
}
func onEvent(_ message: String?) {
handler(message)
}
}