server

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateConfCmd = &cobra.Command{
	Use:     "srvconf",
	Short:   "生成服务器默认yaml配置文件",
	GroupID: "exec",
	Example: "portmap_linux_amd64 srvconf -p config.yaml",
	Run: func(cmd *cobra.Command, args []string) {
		CreateExampleFile(confPath)
	},
}
View Source
var RunCmd = &cobra.Command{
	Use:     "srvrun",
	GroupID: "exec",
	Short:   "运行端口映射服务器",
	Example: "portmap_linux_amd64 srvrun -c config.yaml",
	Run: func(cmd *cobra.Command, args []string) {
		LoadConfigFromYaml(path)
		var instances []*Instance

		for _, instanceConfig := range config.InstanceConfigs {
			instance := NewInstance(instanceConfig)
			instance.Run()
			log.Printf("[info] \n%s\n", instance.String())
			instances = append(instances, instance)
		}
		select {}
	},
}

Functions

func CreateExampleFile

func CreateExampleFile(path string)

func LoadConfigFromYaml

func LoadConfigFromYaml(path string)

LoadConfigFromYaml 是从指定路径中读取配置并加载到全局配置config中 若路径为空,则注入默认配置

Types

type Config

type Config struct {
	InstanceConfigs []InstanceConfig `mapstructure:"instances"`
}

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

func NewInstance

func NewInstance(config InstanceConfig) *Instance

NewInstance 返回一个端口映射实例,同时检测传入的config能否启动该实例

func (*Instance) Run

func (i *Instance) Run()

Run 将运行该端口映射实例,该方法不会阻塞,完成连接的初始化后立即返回

func (*Instance) String

func (i *Instance) String() string

type InstanceConfig

type InstanceConfig struct {

	// WebTcpPort 是用户使用tcp连接时的端口
	WebTcpPort int `mapstruture:"webTcpPort"`

	// WebUdpPort 是用户使用udp连接时的端口
	WebUdpPort int `mapstruture:"webUdpPort"`

	// LinuxPort 是用户映射主机连接服务器的端口
	OutPort int `mapstructure:"outPort"`

	// Password 是用户主机与服务器连接时的口令,以防外人连接
	Password string `mapstructure:"password"`

	// Name 是该映射的名字,用于在映射组中区分其他映射
	Name string `mapstructure:"name"`

	// Key 是服务器与目标主机通信时的加密的Key,长度应为16字节
	Key string `mapstructure:"key"`
}

InstanceConfig 是一个端口映射在服务器端的配置

Jump to

Keyboard shortcuts

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