github.com/imannamdari/v2ray-core/v5@v5.0.5/proxy/trojan/simplified/config.go (about) 1 package simplified 2 3 import ( 4 "context" 5 6 "github.com/imannamdari/v2ray-core/v5/common" 7 "github.com/imannamdari/v2ray-core/v5/common/protocol" 8 "github.com/imannamdari/v2ray-core/v5/common/serial" 9 "github.com/imannamdari/v2ray-core/v5/proxy/trojan" 10 ) 11 12 func init() { 13 common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { 14 simplifiedServer := config.(*ServerConfig) 15 fullServer := &trojan.ServerConfig{ 16 Users: func() (users []*protocol.User) { 17 for _, v := range simplifiedServer.Users { 18 account := &trojan.Account{Password: v} 19 users = append(users, &protocol.User{ 20 Account: serial.ToTypedMessage(account), 21 }) 22 } 23 return 24 }(), 25 PacketEncoding: simplifiedServer.PacketEncoding, 26 } 27 return common.CreateObject(ctx, fullServer) 28 })) 29 30 common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { 31 simplifiedClient := config.(*ClientConfig) 32 fullClient := &trojan.ClientConfig{ 33 Server: []*protocol.ServerEndpoint{ 34 { 35 Address: simplifiedClient.Address, 36 Port: simplifiedClient.Port, 37 User: []*protocol.User{ 38 { 39 Account: serial.ToTypedMessage(&trojan.Account{Password: simplifiedClient.Password}), 40 }, 41 }, 42 }, 43 }, 44 } 45 return common.CreateObject(ctx, fullClient) 46 })) 47 }