tsweb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 10 Imported by: 1

README

Simple Private Virtual Service on Tailscale

This module is intended to remove some of the boilerplate for running simple web services within a tailscale tailnet.

Adding to project

go get -u github.com/kellegous/tsweb

Example Use

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"tailscale.com/tsnet"

	"github.com/kellegous/tsweb"
)

func main() {
	s, err := tsweb.Start(&tsnet.Server{
		AuthKey:  os.Getenv("TS_AUTHKEY"),
		Hostname: "sample",
		Dir:      "data",
	})
	if err != nil {
		log.Panic(err)
	}
	defer s.Close()

	l, err := s.ListenTLS("tcp", ":https")
	if err != nil {
		log.Panic(err)
	}

	log.Panic(
		http.Serve(l, http.HandlerFunc(
			func(w http.ResponseWriter, r *http.Request) {
				fmt.Fprintf(w, "Hello Tailnet")
			},
		)),
	)
}

Authors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	*tsnet.Server
}

func Start

func Start(s *tsnet.Server) (*Service, error)

func (*Service) GetDNSName

func (s *Service) GetDNSName(ctx context.Context) (string, error)

func (*Service) ListenTLS

func (s *Service) ListenTLS(network string, addr string) (net.Listener, error)

func (*Service) RedirectHTTP

func (s *Service) RedirectHTTP(ctx context.Context) error

func (*Service) WaitUntilReady

func (s *Service) WaitUntilReady(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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