packagemainimport ("fmt""github.com/Diarkis/diarkis""your/project/cmds""github.com/Diarkis/diarkis/log""github.com/Diarkis/diarkis/mesh""github.com/Diarkis/diarkis/server/http""os")funcmain() { rootpath, err := os.Getwd()if err !=nil {panic(err) } log.Setup(fmt.Sprintf("%s/configs/shared/log.json", rootpath))// Sets up the internal communication network mesh.Setup(fmt.Sprintf("%s/configs/shared/mesh.json", rootpath))// This sets up HTTP server as Diarkis cluster entry point http.SetupAsAuthServer(fmt.Sprintf("%s/configs/http/main.json", rootpath))// Sets up match making with configurations matching.Setup(fmt.Sprintf("%s/configs/shared/matching.json", rootpath)) cmds.Setup(rootpath)// All HTTP REST API implementations are exposed by calling cmds.ExposeHTTP() cmds.ExposeHTTP() diarkis.Start()}
カスタムHTTP RESTエンドポイントの作成方法
DiarkisのHTTPサーバーでは、カスタムRESTエンドポイントを書くことができます。
cmds/http/main.go
packagehttpcmdsimport ("github.com/Diarkis/diarkis/server/http")funcExpose(rootpath string) {// :message is treated as a parameter and the value can be accessed from *http.Params http.Get("/hello/:message", handleHello)}funchandleHello(res *http.Response, req *http.Request, params *http.Params, next func(error)) { message := params.GetAsString("message") res.Respond(message, http.Ok)// move on to other handlersnext(nil)}
Diarkis Match Makingでは、複数の検索条件を定義することができます。マッチメイキングの定義は、HTTPサーバーで定義する必要があります。
levelAndRank :="levelAndRank"conds :=make(map[string]int)// Search will be in the range of level 0 to 10, 11 to 20, 21 to 30...conds["level"] =10// Search will be in the range of rank 0 to 50, 51 to 100, 101 to 150...conds["rank"] =50// levelAndRank will search against level and rank within their ranges.matching.Define(levelAndRank, conds)
strict ="strict"strictConds :=make(map[string]int)strictConds["power"] =5strictConds["league"] =1// This is the definition of the first strict search conditionmatching.Define(strict, strictConds)lessStrict ="lessStrict"lessStrictConds :=make(map[string]int)lessStrictConds["power"] =10lessStrictConds["league"] =5// This is the second definition and it is less strict than the first conditionmatching.Define(lessStrict, lessStrictConds)