Documentation ¶
Overview ¶
Package mux helps multiplexing gRPC and gRPC Web on the same port, switching on HTTP Content-Type Header. It features insecure clear-text, TLS termination and Onion service
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InsecureOptions ¶
type InsecureOptions struct {
Address string
}
InsecureOptions holds the address where to listen for TCP packets
type Mux ¶
type Mux struct { Listener net.Listener GrpcServer *grpc.Server // contains filtered or unexported fields }
Mux holds a net.Listener, a *grpc.Server and if onion service a *tor.Tor client
func NewMuxWithInsecure ¶
func NewMuxWithInsecure(grpcServer *grpc.Server, opts InsecureOptions) (*Mux, error)
NewMuxWithInsecure returns a clear-text *Mux. Use only for development.
Example ¶
package main import ( "log" "github.com/tiero/grpc-web-mux/pkg/mux" "google.golang.org/grpc" ) func main() { myGrpcServer := grpc.NewServer() insecureMux, err := mux.NewMuxWithInsecure( myGrpcServer, mux.InsecureOptions{Address: ":8080"}, ) if err != nil { log.Panic(err) } log.Printf("Serving mux at %s\n", insecureMux.Listener.Addr().String()) defer insecureMux.Close() insecureMux.Serve() }
Output:
func NewMuxWithOnion ¶
func NewMuxWithOnion(grpcServer *grpc.Server, opts OnionOptions) (*Mux, error)
NewMuxWithOnion returns a *Mux publishing an V3 Onion Service with the given private key and creating an empty datadir in the current working directory. This will take couple of minutes to spin up, so be patient.
Example ¶
package main import ( "log" "github.com/tiero/grpc-web-mux/pkg/mux" "google.golang.org/grpc" ) func main() { myGrpcServer := grpc.NewServer() onionMux, err := mux.NewMuxWithOnion( myGrpcServer, mux.OnionOptions{ Port: 80, PrivateKey: "myBase64SerializedPrivateKey", }, ) if err != nil { log.Panic(err) } log.Printf("Serving mux at %s\n", onionMux.Listener.Addr().String()) defer onionMux.Close() onionMux.Serve() }
Output:
func NewMuxWithTLS ¶
func NewMuxWithTLS(grpcServer *grpc.Server, opts TLSOptions) (*Mux, error)
NewMuxWithTLS returns a *Mux with TLS termination automatically obtaining the TLS certificate with given domain through CertMagic. By default, CertMagic stores assets on the local file system in $HOME/.local/share/certmagic (and honors $XDG_DATA_HOME if set). CertMagic will create the directory if it does not exist. If writes are denied, things will not be happy, so make sure CertMagic can write to it!
Example ¶
package main import ( "log" "github.com/tiero/grpc-web-mux/pkg/mux" "google.golang.org/grpc" ) func main() { myGrpcServer := grpc.NewServer() tlsMux, err := mux.NewMuxWithTLS( myGrpcServer, mux.TLSOptions{ Address: ":9945", Domain: "mydomain.com", }, ) if err != nil { log.Panic(err) } log.Printf("Serving mux at %s\n", tlsMux.Listener.Addr().String()) defer tlsMux.Close() tlsMux.Serve() }
Output:
type OnionOptions ¶
type OnionOptions struct { // The port wich the onion service will listen on Port int //PrivateKey is a base64 blob. If not present, a key is generated based PrivateKey string // DataDir defines where to store temporary files for the Onion service. If empty will be created one in the path of the process DataDir string // DebugWriter holds the debug output. If nil, no ouputs DebugWriter io.Writer }
OnionOptions defines options of onion service. PrivateKey is a base64 blob, if not present, a ED25519 key is generated for OnionV3. DataDir is the directory used by Tor. If it is empty, a temporary directory is created in TempDataDirBase. TempDataDirBase is the parent directory that a temporary data directory will be created under for use by Tor. This is ignored if DataDir is not empty. If empty it is assumed to be the current working directory
type TLSOptions ¶
TLSOptions holds the address where to listen for TCP packets and defines the domain for which we need to obtain and renew a TLS cerficate