server

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package server provides simple tools for Go HTTP servers.

Index

Examples

Constants

View Source
const ErrServerNotReady msg.ConstError = "server not ready"

ErrServerNotReady is returned when WaitFor times out.

Variables

This section is empty.

Functions

func Interrupt

func Interrupt() error

func IsReady

func IsReady(url string) error

IsReady checks to see if the specified URL can be returned correctly. A nil error return signifies the server is ready.

func WaitFor

func WaitFor(url string, timeout time.Duration) error

WaitFor pings server until it is actively serving requests for the specified url. If the server does not properly respond within the timeout an error is returned. A nil error return signifies the server is ready.

Example
if err := IsReady(goodURL); err != nil {
	fmt.Printf("Not Ready 1: %s\n", err)
}

server := runPingService()
defer server.Close()

if err := WaitFor(server.URL, 100*time.Millisecond); err != nil {
	fmt.Printf("Not Ready 2: %s\n", err)
} else {
	fmt.Println("Success!")
}
Output:

Not Ready 1: Get "http://localhost:8080/ping": dial tcp 127.0.0.1:8080: connect: connection refused
Success!

Types

This section is empty.

Jump to

Keyboard shortcuts

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