web

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckVisibility

func CheckVisibility(verbose bool) (map[string]bool, error)

CheckVisibility checks if api server could reach this client machine for each newtwork interface.

func CheckVisibilityIPPort

func CheckVisibilityIPPort(ip, port string, verbose bool) (bool, error)

CheckVisibilityIPPort checks if starting a local server over the given ip and port could be visible by the api server.

func GetAllIP

func GetAllIP() ([]string, error)

GetAllIP gets all the local ip.

func GetOutboundIP

func GetOutboundIP() (string, error)

GetOutboundIP gets the preferred outbound ip of this machine.

func PreferredLocalURL

func PreferredLocalURL(verbose bool) (*url.URL, map[string]bool, error)

PreferredLocalURL returns visible url in following preference: non-localhost > localhost url.

func StartLocalServer

func StartLocalServer(dir, ip, port string, verbose bool) (string, func(), error)

StartLocalServer starts a local server serving dir on random port. If ip is not provided, non-local ip will be used. If port is not provided, a random port will be used.

Types

type Server

type Server struct {
	Directory string
	Address   string
}

Server represents a local web server. Format of `Address` is `ip:port`, or `ip:` to get random port.

func (*Server) ServeStatic

func (s *Server) ServeStatic(verbose bool) (*http.Server, int, error)

ServeStatic starts a static server serving the contents of the `directory` over `address`. It returns the http.Server and random port number with error.

Example
s := Server{Directory: "/tmp"}
staticServer, _, err := s.ServeStatic(true)
if err != nil {
	panic(err)
}

time.Sleep(5 * time.Second)

if err := staticServer.Shutdown(context.TODO()); err != nil {
	panic(err)
}

fmt.Println("Done")
Output:

Done

Jump to

Keyboard shortcuts

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