Skip to content

Commit

Permalink
chore(docs): add docs for public types and functions (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqixu authored May 5, 2023
1 parent ddce1fd commit 29ef189
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// OpAMPClient is an interface representing the client side of the OpAMP protocol.
type OpAMPClient interface {

// Start the client and begin attempts to connect to the Server. Once connection
// is established the client will attempt to maintain it by reconnecting if
// the connection is lost. All failed connection attempts will be reported via
// OnConnectFailed callback.
//
// AgentDescription in settings MUST be set.
// SetAgentDescription() MUST be called before Start().
//
// Start may immediately return an error if the settings are incorrect (e.g. the
// serverURL is not a valid URL).
Expand Down
13 changes: 13 additions & 0 deletions client/types/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// MessageData represents a message received from the server and handled by Callbacks.
type MessageData struct {
// RemoteConfig is offered by the Server. The Agent must process it and call
// OpAMPClient.SetRemoteConfigStatus to indicate success or failure. If the
Expand Down Expand Up @@ -38,6 +39,7 @@ type MessageData struct {
AgentIdentification *protobufs.AgentIdentification
}

// Callbacks is an interface for the Client to handle messages from the Server.
type Callbacks interface {
// OnConnect is called when the connection is successfully established to the Server.
// May be called after Start() is called and every time a connection is established to the Server.
Expand Down Expand Up @@ -116,6 +118,8 @@ type Callbacks interface {
OnCommand(command *protobufs.ServerToAgentCommand) error
}

// CallbacksStruct is a struct that implements Callbacks interface and allows
// to override only the methods that are needed. If a method is not overridden then it is a no-op.
type CallbacksStruct struct {
OnConnectFunc func()
OnConnectFailedFunc func(err error)
Expand All @@ -139,43 +143,50 @@ type CallbacksStruct struct {

var _ Callbacks = (*CallbacksStruct)(nil)

// OnConnect implements Callbacks.OnConnect.
func (c CallbacksStruct) OnConnect() {
if c.OnConnectFunc != nil {
c.OnConnectFunc()
}
}

// OnConnectFailed implements Callbacks.OnConnectFailed.
func (c CallbacksStruct) OnConnectFailed(err error) {
if c.OnConnectFailedFunc != nil {
c.OnConnectFailedFunc(err)
}
}

// OnError implements Callbacks.OnError.
func (c CallbacksStruct) OnError(err *protobufs.ServerErrorResponse) {
if c.OnErrorFunc != nil {
c.OnErrorFunc(err)
}
}

// OnMessage implements Callbacks.OnMessage.
func (c CallbacksStruct) OnMessage(ctx context.Context, msg *MessageData) {
if c.OnMessageFunc != nil {
c.OnMessageFunc(ctx, msg)
}
}

// SaveRemoteConfigStatus implements Callbacks.SaveRemoteConfigStatus.
func (c CallbacksStruct) SaveRemoteConfigStatus(ctx context.Context, status *protobufs.RemoteConfigStatus) {
if c.SaveRemoteConfigStatusFunc != nil {
c.SaveRemoteConfigStatusFunc(ctx, status)
}
}

// GetEffectiveConfig implements Callbacks.GetEffectiveConfig.
func (c CallbacksStruct) GetEffectiveConfig(ctx context.Context) (*protobufs.EffectiveConfig, error) {
if c.GetEffectiveConfigFunc != nil {
return c.GetEffectiveConfigFunc(ctx)
}
return nil, nil
}

// OnOpampConnectionSettings implements Callbacks.OnOpampConnectionSettings.
func (c CallbacksStruct) OnOpampConnectionSettings(
ctx context.Context, settings *protobufs.OpAMPConnectionSettings,
) error {
Expand All @@ -185,12 +196,14 @@ func (c CallbacksStruct) OnOpampConnectionSettings(
return nil
}

// OnOpampConnectionSettingsAccepted implements Callbacks.OnOpampConnectionSettingsAccepted.
func (c CallbacksStruct) OnOpampConnectionSettingsAccepted(settings *protobufs.OpAMPConnectionSettings) {
if c.OnOpampConnectionSettingsAcceptedFunc != nil {
c.OnOpampConnectionSettingsAcceptedFunc(settings)
}
}

// OnCommand implements Callbacks.OnCommand.
func (c CallbacksStruct) OnCommand(command *protobufs.ServerToAgentCommand) error {
if c.OnCommandFunc != nil {
return c.OnCommandFunc(command)
Expand Down
1 change: 1 addition & 0 deletions client/types/logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package types

// Logger is the logging interface used by the OpAMP Client.
type Logger interface {
Debugf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Expand Down
1 change: 1 addition & 0 deletions client/types/packagessyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PackagesSyncer interface {
Done() <-chan struct{}
}

// PackageState represents the state of a package in the Agent's local storage.
type PackageState struct {
// Exists indicates that the package exists locally. The rest of the fields
// must be ignored if this field is false.
Expand Down
1 change: 1 addition & 0 deletions client/types/startsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/open-telemetry/opamp-go/protobufs"
)

// StartSettings defines the parameters for starting the OpAMP Client.
type StartSettings struct {
// Connection parameters.

Expand Down

0 comments on commit 29ef189

Please sign in to comment.