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

chore: add doc comments to server API #215

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import (
"github.com/open-telemetry/opamp-go/server/types"
)

// 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 will
// accept all connections.
type CallbacksStruct struct {
OnConnectingFunc func(request *http.Request) types.ConnectionResponse
}

var _ types.Callbacks = (*CallbacksStruct)(nil)

// OnConnecting implements Callbacks.interface.
func (c CallbacksStruct) OnConnecting(request *http.Request) types.ConnectionResponse {
if c.OnConnectingFunc != nil {
return c.OnConnectingFunc(request)
}
return types.ConnectionResponse{Accept: true}
}

// ConnectionCallbacksStruct is a struct that implements ConnectionCallbacks interface and allows
// to override only the methods that are needed.
type ConnectionCallbacksStruct struct {
OnConnectedFunc func(conn types.Connection)
OnMessageFunc func(conn types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent
Expand All @@ -28,12 +34,15 @@ type ConnectionCallbacksStruct struct {

var _ types.ConnectionCallbacks = (*ConnectionCallbacksStruct)(nil)

// OnConnected implements ConnectionCallbacks.OnConnected.
func (c ConnectionCallbacksStruct) OnConnected(conn types.Connection) {
if c.OnConnectedFunc != nil {
c.OnConnectedFunc(conn)
}
}

// OnMessage implements ConnectionCallbacks.OnMessage.
// If OnMessageFunc is nil then it will send an empty response to the agent
func (c ConnectionCallbacksStruct) OnMessage(conn types.Connection, message *protobufs.AgentToServer) *protobufs.ServerToAgent {
if c.OnMessageFunc != nil {
return c.OnMessageFunc(conn, message)
Expand All @@ -45,6 +54,7 @@ func (c ConnectionCallbacksStruct) OnMessage(conn types.Connection, message *pro
}
}

// OnConnectionClose implements ConnectionCallbacks.OnConnectionClose.
func (c ConnectionCallbacksStruct) OnConnectionClose(conn types.Connection) {
if c.OnConnectionCloseFunc != nil {
c.OnConnectionCloseFunc(conn)
Expand Down
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/open-telemetry/opamp-go/server/types"
)

// Settings contains the settings for attaching an OpAMP Server.
type Settings struct {
// Callbacks that the Server will call after successful Attach/Start.
Callbacks types.Callbacks
Expand All @@ -19,6 +20,7 @@ type Settings struct {
EnableCompression bool
}

// StartSettings contains the settings for starting an OpAMP Server.
type StartSettings struct {
Settings

Expand All @@ -37,6 +39,7 @@ type HTTPHandlerFunc func(http.ResponseWriter, *http.Request)

type ConnContext func(ctx context.Context, c net.Conn) context.Context

// OpAMPServer is an interface representing the server side of the OpAMP protocol.
type OpAMPServer interface {
// Attach prepares the OpAMP Server to begin handling requests from an existing
// http.Server. The returned HTTPHandlerFunc and ConnContext should be added as a
Expand Down
1 change: 1 addition & 0 deletions server/serverimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type server struct {

var _ OpAMPServer = (*server)(nil)

// New creates a new OpAMP Server.
func New(logger types.Logger) *server {
if logger == nil {
logger = &internal.NopLogger{}
Expand Down
Loading