ufo

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 17 Imported by: 0

README

ufo

Listening on TCP port 0 makes the system allocate a random port for you.

...
  ln, err := net.Listen("tcp", ":0")
  if err != nil {
          return err
  }
  log.Println("listening on", ln.Addr().String())
  return http.Serve(ln, http.FileServer(http.Dir(".")))
...

2022/09/24 23:09:17 listening on ::48982

Taking inspiration from that, ufo is a Golang service that allocates random subdomains to clients with automatic SSL, HTTP/3 for free.

The programming interface is the almost the same as [net.Listen]

...
  ln, err := ufo.Listen("https://ufo.k0s.io")
  if err != nil {
          return err
  }
  log.Println("listening on", ln.AutoURL())
  return http.Serve(ln, http.FileServer(http.Dir(".")))
...

2022/09/24 23:09:17 listening on https://1.ufo.k0s.io

deploy server:

$ kubectl apply -f https://raw.githubusercontent.com/btwiuse/ufo/main/deploy.yaml

install client:

$ go install github.com/btwiuse/ufo/cmd/ufo@latest

example apps:

$ ufo hello
$ ufo gos
$ ufo sse
$ ufo echo

TODO

  • support concurrent rw on session manager map
  • support custom root domain, for example HOST=ufo.dev
  • support user specified hostname
  • authentication plugins: netrc, basic auth, environment variable
  • reverseproxy WebTransport requests

Documentation

Index

Constants

View Source
const MaxIncomingStreams int64 = 1 << 60

2^60 == 1152921504606846976

Variables

This section is empty.

Functions

func Dial added in v0.0.3

func Dial(ctx context.Context, u *url.URL, hdr http.Header) (*webtransport.Session, error)

Dial is a wrapper around webtransport.Dial with automatic HTTP/3 service discovery

func ExtractAltSvcEndpoints added in v0.0.7

func ExtractAltSvcEndpoints(h http.Header, protocolId string) []string

ExtractAltSvcH3Endpoints reads Alt-Svc header returns a list of [host]:port endpoints

func ExtractURLPort added in v0.0.7

func ExtractURLPort(u *url.URL) string

ExtractURLPort returns the :port part from URL.Host (host[:port])

An empty string is returned if no port is found

func Graft added in v0.0.7

func Graft(base, alt string) string

Graft returns Host(base):Port(alt)

assuming - base is host[:port] - alt is [host]:port

func Hyperlink(name, url string) string

Print Hyperlink via OSC 8 ansi sequence. The syntax is: 'OSC 8 ; params ; url ST text OSC 8 ; ; ST' for more info see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

func Listen

func Listen(u string) (*listener, error)
func MaybeHyperlink(l string) string

MaybeHyperlink turns input into ANSI hyperlink when stdin is a tty

func Serve added in v0.0.3

func Serve(u string, handler http.Handler) error

func ToIdna added in v0.0.6

func ToIdna(s string) string

ToIdna converts a string to its idna form at best effort Should only be used on the hostname part without port

Types

type StreamConn

type StreamConn struct {
	webtransport.Stream
	Session *webtransport.Session
}

StreamsConn wraps webtransport.Stream into net.Conn

func (*StreamConn) LocalAddr

func (sc *StreamConn) LocalAddr() net.Addr

LocalAddr is required to impl net.Conn

func (*StreamConn) RemoteAddr

func (sc *StreamConn) RemoteAddr() net.Addr

RemoteAddr is required to impl net.Conn

Directories

Path Synopsis
cmd
echo command
gos command
hello command
idna command
randport command
sse command
ufo command

Jump to

Keyboard shortcuts

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