mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package tunnel
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/micro/go-micro/transport"
|
|
"github.com/micro/go-micro/transport/quic"
|
|
)
|
|
|
|
var (
|
|
// DefaultAddress is default tunnel bind address
|
|
DefaultAddress = ":0"
|
|
// The shared default token
|
|
DefaultToken = "micro"
|
|
)
|
|
|
|
type Option func(*Options)
|
|
|
|
// Options provides network configuration options
|
|
type Options struct {
|
|
// Id is tunnel id
|
|
Id string
|
|
// Address is tunnel address
|
|
Address string
|
|
// Nodes are remote nodes
|
|
Nodes []string
|
|
// The shared auth token
|
|
Token string
|
|
// Transport listens to incoming connections
|
|
Transport transport.Transport
|
|
}
|
|
|
|
// The tunnel id
|
|
func Id(id string) Option {
|
|
return func(o *Options) {
|
|
o.Id = id
|
|
}
|
|
}
|
|
|
|
// The tunnel address
|
|
func Address(a string) Option {
|
|
return func(o *Options) {
|
|
o.Address = a
|
|
}
|
|
}
|
|
|
|
// Nodes specify remote network nodes
|
|
func Nodes(n ...string) Option {
|
|
return func(o *Options) {
|
|
o.Nodes = n
|
|
}
|
|
}
|
|
|
|
// Token sets the shared token for auth
|
|
func Token(t string) Option {
|
|
return func(o *Options) {
|
|
o.Token = t
|
|
}
|
|
}
|
|
|
|
// Transport listens for incoming connections
|
|
func Transport(t transport.Transport) Option {
|
|
return func(o *Options) {
|
|
o.Transport = t
|
|
}
|
|
}
|
|
|
|
// DefaultOptions returns router default options
|
|
func DefaultOptions() Options {
|
|
return Options{
|
|
Id: uuid.New().String(),
|
|
Address: DefaultAddress,
|
|
Token: DefaultToken,
|
|
Transport: quic.NewTransport(),
|
|
}
|
|
}
|