socket

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildNotifier

type BuildNotifier interface {
	NotifyLog(buildID string, stream string, content string)
	NotifyStatus(buildID, status, artifactRef string, buildErr error, duration *float64)
}

type BuildQueuedPayload

type BuildQueuedPayload struct {
	BuildID string `json:"build_id"` // UID for this build assigned by the server
	Message string `json:"message"`  // e.g., "Build job accepted and queued"
}

type BuildRequestPayload

type BuildRequestPayload struct {
	BuildSpecYAML string `json:"build_spec_yaml"`
}

type BuildStatusPayload

type BuildStatusPayload struct {
	BuildID     string   `json:"build_id"`
	Status      string   `json:"status"`                 // e.g., "queued", "fetching", "building", "success", "failure"
	Message     string   `json:"message,omitempty"`      // additional Message (e.g., failure reason)
	ArtifactRef string   `json:"artifact_ref,omitempty"` // The ref of the actual completed build (URL, path B2, tag Docker, etc.)
	DurationSec *float64 `json:"duration_sec,omitempty"`
}

The actual build status.

type BuildTriggerer

type BuildTriggerer interface {
	StartBuildAsync(ctx context.Context, buildID string, buildSpecYAML string, notifier BuildNotifier) error
}

type Client

type Client struct {

	// Incoming messages are pushed here by the readPump.
	// Users can read from this channel to process incoming messages.
	Incoming chan *Message // Public channel for incoming messages
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

Creating a new client for a websocket connection.

func (*Client) Close

func (c *Client) Close()

Close the websocket connection and stopping the client.

func (*Client) Connect

func (c *Client) Connect(serverUrl string, headers http.Header) error

Connect to the given server url websocket with the provided headers.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

func (*Client) Send

func (c *Client) Send(msg *Message) error

sending message to the server asynchronously.

func (*Client) SendRequest

func (c *Client) SendRequest(ctx context.Context, msgType EventType, payload any) (*Message, error)

sending a request and waiting for the response based on the RequestID.

type ErrorPayload

type ErrorPayload struct {
	Code    int    `json:"code,omitempty"`
	Details string `json:"details"`
}

type EventType

type EventType string
const (
	// Client -> Server
	EvtBuildRequest  EventType = "build_request"  // Build request
	EvtSecretRequest EventType = "secret_request" // Secret fetching request

	// Server -> Client
	EvtBuildQueued    EventType = "build_queued"    // Queued build response message
	EvtLogChunk       EventType = "log_chunk"       // A build part log result
	EvtBuildStatus    EventType = "build_status"    // Updating the build status (running, success, failure)
	EvtSecretResponse EventType = "secret_response" // Secret request response
	EvtError          EventType = "error"           // A standard error message for any event

	EvtPing EventType = "ping"
	EvtPong EventType = "pong"
)

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

type LogChunkPayload

type LogChunkPayload struct {
	BuildID string `json:"build_id"`
	Stream  string `json:"stream"` // "stdout" or "stderr" (or "system")
	Content string `json:"content"`
}

The log message chunk.

type Message

type Message struct {
	Type      EventType       `json:"type"` // The event type (needed)
	RequestID string          `json:"request_id,omitempty"`
	Payload   json.RawMessage `json:"payload,omitempty"` // Event specific data (raw JSON)
	Error     string          `json:"error,omitempty"`   // Event message if Type=EvtError or for negative error message
}

func NewErrorMessage

func NewErrorMessage(requestID, errMsg, details string) *Message

func NewMessage

func NewMessage(eventType EventType, requestID string) *Message

func (*Message) AddPayload

func (m *Message) AddPayload(payload interface{}) error

func (*Message) DecodePayload

func (m *Message) DecodePayload(target interface{}) error

type SecretFetcher

type SecretFetcher interface {
	GetSecret(ctx context.Context, source string) (string, error)
}

type SecretRequestPayload

type SecretRequestPayload struct {
	Source string `json:"source"`
}

type SecretResponsePayload

type SecretResponsePayload struct {
	Source string `json:"source"`
	Value  string `json:"value"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(buildSvc BuildTriggerer, secretF SecretFetcher, originChecker func(r *http.Request) bool) *Server

Creating a new Websocket server and upgrading connection

func (*Server) Run

func (s *Server) Run()

Launching the Hub in a goroutine.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Handling http request and trying to upgrade it to a websocket connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL