github.com/godaddy-x/freego@v1.0.156/main.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/godaddy-x/freego/cache"
     5  	"github.com/godaddy-x/freego/cache/limiter"
     6  	ballast "github.com/godaddy-x/freego/gc"
     7  	"github.com/godaddy-x/freego/node/test"
     8  	"github.com/godaddy-x/freego/ormx/sqld"
     9  	"github.com/godaddy-x/freego/rpcx"
    10  	"github.com/godaddy-x/freego/utils"
    11  	_ "go.uber.org/automaxprocs"
    12  	"net/http"
    13  	_ "net/http/pprof"
    14  )
    15  
    16  func http_test() {
    17  	//go http_web.StartHttpNode1()
    18  	//go http_web.StartHttpNode2()
    19  	sqld.RebuildMongoDBIndex()
    20  	http_web.StartHttpNode()
    21  }
    22  
    23  func initConsul() {
    24  	conf := rpcx.ConsulConfig{}
    25  	if err := utils.ReadLocalJsonConfig("resource/consul.json", &conf); err != nil {
    26  		panic(utils.AddStr("读取consul配置失败: ", err.Error()))
    27  	}
    28  	new(rpcx.ConsulManager).InitConfig(conf)
    29  }
    30  
    31  func initRedis() {
    32  	conf := cache.RedisConfig{}
    33  	if err := utils.ReadLocalJsonConfig("resource/redis.json", &conf); err != nil {
    34  		panic(utils.AddStr("读取redis配置失败: ", err.Error()))
    35  	}
    36  	new(cache.RedisManager).InitConfig(conf)
    37  }
    38  
    39  var appConfig = rpcx.AppConfig{}
    40  
    41  func initGRPC() {
    42  	if err := utils.ReadLocalJsonConfig("resource/app.json", &appConfig); err != nil {
    43  		panic(err)
    44  	}
    45  	client := &rpcx.GRPCManager{}
    46  	client.CreateJwtConfig(appConfig.AppKey)
    47  	client.CreateAppConfigCall(func(appId string) (rpcx.AppConfig, error) {
    48  		if appId == appConfig.AppId {
    49  			return appConfig, nil
    50  		}
    51  		return rpcx.AppConfig{}, utils.Error("appId invalid")
    52  	})
    53  	client.CreateRateLimiterCall(func(method string) (rate.Option, error) {
    54  		return rate.Option{}, nil
    55  	})
    56  	client.CreateServerTLS(rpcx.TlsConfig{
    57  		UseMTLS:   true,
    58  		CACrtFile: "./rpcx/cert/ca.crt",
    59  		KeyFile:   "./rpcx/cert/server.key",
    60  		CrtFile:   "./rpcx/cert/server.crt",
    61  	})
    62  	client.CreateClientTLS(rpcx.TlsConfig{
    63  		UseMTLS:   true,
    64  		CACrtFile: "./rpcx/cert/ca.crt",
    65  		KeyFile:   "./rpcx/cert/client.key",
    66  		CrtFile:   "./rpcx/cert/client.crt",
    67  		HostName:  "localhost",
    68  	})
    69  	client.CreateAuthorizeTLS("./rpcx/cert/server.key")
    70  }
    71  
    72  func init() {
    73  	//initConsul()
    74  	//initRedis()
    75  	//initGRPC()
    76  }
    77  
    78  func main() {
    79  	ballast.GC(512*ballast.MB, 30)
    80  	go func() {
    81  		_ = http.ListenAndServe(":8849", nil)
    82  	}()
    83  	//rpcx.RunClient(appConfig.AppId)
    84  	http_test()
    85  	//router := fasthttprouter.New()
    86  	//router.GET("/pubkey", func(ctx *fasthttp.RequestCtx) {
    87  	//	ctx.WriteString("LS0tLS1CRUdJTiBSU0EgUFVCTElDSyBLRVktLS0tLQpNSUdKQW9HQkFMK2hpYkw5S3hpb2JNOVRPbmx6cXN0WnhPSy9rU2JQQzMzSmpoVTdjbklUbXlRaThuaXZiUG5wCncwOUo5N0p4aDdxY0tOWVhpakxRdTZxei9xUFNXZ0pYaU9qOWhoc2E0bEdlNVVkRkJtaFpxZ2V3R1J6ckJJNEkKRFNqZk1xcDNCM3puV1h1VnBaSFZNYStJOFBDc1A5dEd3dzdPS2hzRFI0bmp3L3Z2UXdERkFnTUJBQUU9Ci0tLS0tRU5EIFJTQSBQVUJMSUNLIEtFWS0tLS0tCg==")
    88  	//})
    89  	//fasthttp.ListenAndServe(":8090", router.Handler)
    90  }