Skip to content

Go package for starting a local webserver and then opening its URL in a target source once it (the web server) is running.

License

Notifications You must be signed in to change notification settings

sfomuseum/go-www-show

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-www-show

Go package for starting a local webserver and then opening its URL in a target source once it (the web server) is running.

Usage

This package is meant to be used by other packages that have configured a http.Mux instance for serving web requests. The package will start a web server on localhost listening on a randomly chose port number (unless a user-defined value is provided) and then open that URL in a target environment (like a web browser).

import (
	"context"
	"net/http"

	"github.com/sfomuseum/go-www-show"
)

func main() {

	ctx := context.Background()
	
	mux := http.NewServeMux()
	
	// Configure handlers for mux here

	browser, _ = show.NewBrowser(ctx, "web://")
	
        show_opts := &www_show.RunOptions{
                Browser: browser,
                Mux:     mux,
        }

        return show.RunWithOptions(ctx, www_show_opts)
}

This package defines a Browser interface for opening URLs. Currently there is only a single implementation (web) for opening URLs in the operating system's default web browser. In the future there may be other implementations to "open" a URL by delivering it to a remote service that handles opening and displaying that URL.

For a complete working example see the sfomuseum/go-geojson-show package.

About

Go package for starting a local webserver and then opening its URL in a target source once it (the web server) is running.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages