Setup Field Module on Server

Overview

The Field module needs to be set up on HTTP, UDP, and TCP servers. The memory data of Field is managed on the HTTP server, and the built-in commands are made available by publishing them on UDP and TCP servers.

Setup

Add the following code to the main function of the HTTP server:

package main

import "github.com/Diarkis/diarkis/diarkisexec"

func main() {
	logConfigPath := "/configs/shared/log.json"
	meshConfigPath := "/configs/shared/mesh.json"

	diarkisexec.SetupDiarkis(logConfigPath, meshConfigPath, &diarkisexec.Modules{
		Field: &diarkisexec.Options{ConfigPath: "/configs/shared/field.json", ExposeCommands: true},
	})

	diarkisexec.SetupDiarkisHTTPServer("/configs/http/main.json")
	diarkisexec.StartDiarkis()
}

To expose the built-in commands to the client, you can use the diarkisexec package to set them up. Similarly, add the following to the main function of the UDP and TCP servers. Here is an example setup for a UDP server. The setup function of diarkisexec must be executed before calling diarkisexec.StartDiarkis().

For more details, please refer to the diarkisexec API Reference.

package main

import "github.com/Diarkis/diarkis/diarkisexec"

func main() {
	logConfigPath := "/configs/shared/log.json"
	meshConfigPath := ""

	diarkisexec.SetupDiarkis(logConfigPath, meshConfigPath, &diarkisexec.Modules{
		Field: &diarkisexec.Options{ConfigPath: "/configs/shared/field.json", ExposeCommands: true},
	})
	diarkisexec.SetupDiarkisUDPServer("/configs/udp/main.json")
	diarkisexec.StartDiarkis()
}

Since you can easily launch a server using the server template, it is recommended to use this first. Refer to Diarkis Server Template.

Last updated