@@ -61,7 +61,9 @@ import (
|
||||
|
||||
type (
|
||||
Implm struct {
|
||||
cfg config
|
||||
cfg config
|
||||
ready chan struct{}
|
||||
readyOnce sync.Once
|
||||
}
|
||||
|
||||
config struct {
|
||||
@@ -89,10 +91,12 @@ type (
|
||||
var (
|
||||
_ unit.Configurable = (*Implm)(nil)
|
||||
_ unit.Runnable = (*Implm)(nil)
|
||||
_ unit.Readyable = (*Implm)(nil)
|
||||
)
|
||||
|
||||
func New() *Implm {
|
||||
return &Implm{
|
||||
ready: make(chan struct{}),
|
||||
cfg: config{
|
||||
BaseURL: baseurl.MustParse("http://localhost:8080"),
|
||||
Api: apiConfig{
|
||||
@@ -173,6 +177,18 @@ func (impl *Implm) GetConfiguration() any {
|
||||
return &impl.cfg
|
||||
}
|
||||
|
||||
// GetAPIAddr returns the API server address (e.g., "localhost:8080").
|
||||
// This is useful for tests to know which address to connect to.
|
||||
func (impl *Implm) GetAPIAddr() string {
|
||||
return impl.cfg.Api.Addr
|
||||
}
|
||||
|
||||
// Ready returns a channel that is closed when the server is ready to accept requests.
|
||||
// This implements the unit.Readyable interface for testing purposes.
|
||||
func (impl *Implm) Ready() <-chan struct{} {
|
||||
return impl.ready
|
||||
}
|
||||
|
||||
func (impl *Implm) Run(
|
||||
parentCtx context.Context,
|
||||
l *log.Logger,
|
||||
@@ -578,6 +594,11 @@ func (impl *Implm) runApiServer(
|
||||
l.Info("api server started")
|
||||
span.AddEvent("API server started")
|
||||
|
||||
// Signal that the server is ready to accept requests
|
||||
impl.readyOnce.Do(func() {
|
||||
close(impl.ready)
|
||||
})
|
||||
|
||||
select {
|
||||
case err := <-serverErrCh:
|
||||
if err != nil {
|
||||
|
||||
21
pkg/ref/ref.go
Normal file
21
pkg/ref/ref.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
// Package ref provides helper functions for working with pointers.
|
||||
package ref
|
||||
|
||||
// Ref returns a pointer to the given value.
|
||||
func Ref[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
Reference in New Issue
Block a user