Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding language binding for golang #1483

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Added utility functions `isStandardContextType(contextType: string)`, `isStandardIntent(intent: string)`,`getPossibleContextsForIntent(intent: StandardIntent)`. ([#1139](https://github.com/finos/FDC3/pull/1139))
* Added support for event listening outside of intent or context listnener. Added new function `addEventListener`, type `EventHandler`, enum `FDC3EventType` and interfaces `FDC3Event` and `FDC3ChannelChangedEvent`. ([#1207](https://github.com/finos/FDC3/pull/1207))
* Added new `CreateOrUpdateProfile` intent. ([#1359](https://github.com/finos/FDC3/pull/1359))
* Added Go language binding. ([#1483](https://github.com/finos/FDC3/pull/1483))

### Changed

Expand Down
158 changes: 158 additions & 0 deletions docs/api/ref/Channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ interface IChannel: IIntentResult
}
```

</TabItem>
<TabItem value="golang" label="Go">

```go
type IChannel interface {
Broadcast(context Context) <-chan Result[any]
GetCurrentContext(contextType string) <-chan Result[Context]
AddContextListener(contextType string, handler ContextHandler) <-chan Result[Listener]
}

type Channel struct {
Id string `json:"id"`
Type ChannelType `json:"type"`
DisplayMetadata *DisplayMetadata `json:"displayMetadata"`
}

type ChannelType string

const (
App ChannelType = "app"
Private ChannelType = "private"
User ChannelType = "user"
System ChannelType = "system"
)
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -89,6 +115,13 @@ public readonly id: string;
string Id { get; }
```

</TabItem>
<TabItem value="golang" label="Go">

```go
Id string
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -117,6 +150,18 @@ public enum ChannelType
}
```

</TabItem>
<TabItem value="golang" label="Go">

```go
type ChannelType string

const (
App ChannelType = "app"
System ChannelType = "system"
Private ChannelType = "private"
)
```
</TabItem>
</Tabs>

Expand All @@ -138,6 +183,12 @@ public readonly displayMetadata?: DisplayMetadata;
IDisplayMetadata? DisplayMetadata { get; }
```

</TabItem>
<TabItem value="golang" label="Go">

```go
DisplayMetadata *DisplayMetadata
```
</TabItem>
</Tabs>

Expand Down Expand Up @@ -165,6 +216,15 @@ public addContextListener(contextType: string | null, handler: ContextHandler):
Task<IListener> AddContextListener<T>(string? contextType, ContextHandler<T> handler) where T : IContext;
```

</TabItem>
<TabItem value="golang" label="Go">

```go
func (ch *Channel) AddContextListener(contextType string, handler ContextHandler) <-chan Result[Listener] {
// Implementation here
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -213,6 +273,24 @@ var listener = await channel.AddContextListener<IContext>(null, (context, metada
listener.Unsubscribe();
```

</TabItem>
<TabItem value="golang" label="Go">

```go
listenerResult := <-channel.AddContextListener("", func(context Context, contextMetadata *ContextMetadata) {
if context.Type == "fdc3.contact" {
// handle the contact
} else if context.Type == "fdc3.instrument" {
// handle the instrument
}
})

// later
if listenerResult.Value != nil {
listenerResult.Value.Unsubscribe()
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -252,6 +330,26 @@ contactListener.unsubscribe();
instrumentListener.unsubscribe();
```

</TabItem>
<TabItem value="golang" label="Go">

```go
listenerResultContact := <-channel.AddContextListener("fdc3.contact", func(context Context, contextMetadata *ContextMetadata) {
// handle the contact
})
listenerResultInstrument := <-channel.AddContextListener("fdc3.instrument", func(context Context, contextMetadata *ContextMetadata) {
// handle the instrument
})

// later
if listenerResultContact.Value != nil {
listenerResultContact.Value.Unsubscribe()
}
if listenerResultInstrument.Value != nil {
listenerResultInstrument.Value.Unsubscribe()
}
```

</TabItem>
</Tabs>

Expand All @@ -278,6 +376,15 @@ public broadcast(context: Context): Promise<void>;
Task Broadcast(IContext context);
```

</TabItem>
<TabItem value="golang" label="Go">

```go
func (channel *Channel) Broadcast(context Context) <-chan Result[any] {
// Implementation here
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -327,6 +434,21 @@ catch (Exception ex)
}
```

</TabItem>
<TabItem value="golang" label="Go">

```go
result := <-myChannel.Broadcast(types.Context{
Type: "fdc3.instrument",
Id: map[string]string{
"ticker": "AAPL",
},
})
if result.Err != null {
// handle error
}
```

</TabItem>
</Tabs>

Expand All @@ -352,6 +474,15 @@ public getCurrentContext(contextType?: string): Promise<Context|null>;
Task<IContext?> GetCurrentContext(string? contextType);
```

</TabItem>
<TabItem value="golang" label="Go">

```go
func (channel *Channel) GetCurrentContext(contextType string) <-chan Result[Context] {
// Implementation here
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -392,6 +523,16 @@ catch (Exception ex)
}
```

</TabItem>
<TabItem value="golang" label="Go">

```go
result := <-myChannel.GetCurrentContext("")
if result.Err != null {
// handle error
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -422,6 +563,16 @@ catch (Exception ex)
}
```

</TabItem>
<TabItem value="golang" label="Go">

```go
result := <-myChannel.GetCurrentContext("fdc3.contact")
if result.Err != null {
// handle error
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -452,6 +603,13 @@ public addContextListener(handler: ContextHandler): Promise<Listener>;
Not implemented
```

</TabItem>
<TabItem value="golang" label="Go">

```
Not implemented
```

</TabItem>

</Tabs>
Expand Down
Loading