코딩 & 연구 중
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"encoding/pem"
"fmt"
"math/big"
"github.com/lucas-clemente/quic-go/http3"
)
const addr = "121.126.208.231:4242"
// We start a server echoing data on the first stream the client opens,
// then connect with a client, send the message, and wait for its receipt.
func main() {
certFile, keyFile := GetCertificatePaths()
fmt.Println(certFile)
fmt.Println(keyFile)
fmt.Println("HTTP3 SERVER START")
//http3.ListenAndServe(addr, generateTLSConfig(), nil)
http3.ListenAndServe(addr, certFile, keyFile, nil)
fmt.Println("HTTP3 SERVER CLOSE")
}
// Setup a bare-bones TLS config for the server
func generateTLSConfig() *tls.Config {
key, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
panic(err)
}
template := x509.Certificate{SerialNumber: big.NewInt(1)}
certDER, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
if err != nil {
panic(err)
}
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER})
tlsCert, err := tls.X509KeyPair(certPEM, keyPEM)
if err != nil {
panic(err)
}
return &tls.Config{
Certificates: []tls.Certificate{tlsCert},
NextProtos: []string{"quic-echo-example"},
}
}
package main
type TestReqMsg struct {
TestMsg string `json:"testmsg"`
}
type TestRespMsg struct {
Result Res `json:"result"`
}
type Res struct {
Code string
Msg string
}