本文整理匯總了Golang中v2ray/com/core/common.Must函數的典型用法代碼示例。如果您正苦於以下問題:Golang Must函數的具體用法?Golang Must怎麽用?Golang Must使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Must函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GenerateCertificateForTest
func GenerateCertificateForTest() *v2tls.Certificate {
priv, err := rsa.GenerateKey(rand.Reader, 2048)
common.Must(err)
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Fatalf("failed to generate serial number: %s", err)
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Organization: []string{"V2Ray Inc"},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
DNSNames: []string{"www.v2ray.com"},
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
common.Must(err)
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
return &v2tls.Certificate{
Certificate: certPEM,
Key: keyPEM,
}
}
示例2: pickPort
func pickPort() v2net.Port {
listener, err := net.Listen("tcp4", ":0")
common.Must(err)
defer listener.Close()
addr := listener.Addr().(*net.TCPAddr)
return v2net.Port(addr.Port)
}
示例3: init
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_UDP,
func(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
src := internet.DialerSourceFromContext(ctx)
conn, err := internet.DialSystem(src, dest)
if err != nil {
return nil, err
}
// TODO: handle dialer options
return internal.NewConnection(internal.NewConnectionID(src, dest), conn, internal.NoOpConnectionRecyler{}, internal.ReuseConnection(false)), nil
}))
}
示例4: EnsureChunk
func (v *AuthenticationReader) EnsureChunk() error {
for {
err := v.NextChunk()
if err == nil {
return nil
}
if err == errInsufficientBuffer {
if v.buffer.IsEmpty() {
v.buffer.Clear()
} else {
leftover := v.buffer.Bytes()
common.Must(v.buffer.Reset(func(b []byte) (int, error) {
return copy(b, leftover), nil
}))
}
err = v.buffer.AppendSupplier(buf.ReadFrom(v.reader))
if err == nil {
continue
}
}
return err
}
}
示例5: init
func init() {
common.Must(common.RegisterConfig((*dispatcher.Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return NewDefaultDispatcher(ctx, config.(*dispatcher.Config))
}))
}
示例6: init
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_TCP, func() interface{} {
return new(Config)
}))
}
示例7: init
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_MKCP, ListenKCP))
}
示例8: init
func init() {
common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return NewServer(ctx, config.(*ServerConfig))
}))
}
示例9: init
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_WebSocket, ListenWS))
}
示例10: init
func init() {
common.Must(common.RegisterConfig((*VideoConfig)(nil), NewVideoChat))
}
示例11: init
func init() {
common.Must(common.RegisterConfig((*proxyman.OutboundConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return New(ctx, config.(*proxyman.OutboundConfig))
}))
}
示例12: init
func init() {
common.Must(common.RegisterConfig((*Config)(nil), NewNoOpHeader))
common.Must(common.RegisterConfig((*ConnectionConfig)(nil), NewNoOpConnectionHeader))
}
示例13: init
func init() {
common.Must(common.RegisterConfig((*Config)(nil), NewSRTP))
}
示例14: init
func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return NewHttpAuthenticator(ctx, config.(*Config))
}))
}