hello-world

command
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 7 Imported by: 0

README

Hello World Example

This is the smallest complete HyperServe application. It includes orderly Ctrl+C shutdown rather than hiding process-signal ownership in the library.

What This Example Shows

  • Creating a basic HyperServe server
  • Handling HTTP requests with a simple handler function
  • Returning a text response

Running the Example

go run main.go

The server will start on http://localhost:8080

Testing the Server

In another terminal, use curl to test:

curl http://localhost:8080/
# Output: Hello, World from HyperServe!

Or open http://localhost:8080 in your web browser.

Code Breakdown

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

srv, err := server.NewServer()
if err != nil {
	log.Fatal(err)
}

// Register a handler for the root path
srv.HandleFunc("/", handler)

// Run blocks until Ctrl+C cancels ctx.
if err := srv.Run(ctx); err != nil {
	log.Fatal(err)
}

The extra context lines are ordinary Go lifecycle plumbing. They make it clear that the application owns process signals while HyperServe owns cleanup of the listeners and workers it starts.

What's Next?

  • Try changing the response message
  • Add another route like /about
  • Move on to static-files to serve HTML files

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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