yats.git

ref: bc892b1b0bc1b6d369f80c49bf597bbe01b5546c

server/main.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * Yats - yats
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2024
 */

package main

import (
	"fmt"
	"os"
	"yats-server/config"
	"yats-server/db"
	"yats-server/docs"
	"yats-server/grpc"
)

var configuration config.Configuration
var instanceName = "default"

// @title           Yats Server
// @version         1.0
// @description     Yet Another Time Serie
// @termsOfService  https://kevwe.com/ TODO

// @contact.name   API Support
// @contact.url    https:// TODO
// @contact.email           TODO

// @license.name  Affero GPL
// @license.url   https://www.gnu.org/licenses/agpl-3.0.en.html#license-text

// @BasePath  /

// @externalDocs.description  OpenAPI
// @externalDocs.url          https://swagger.io/resources/open-api/
func main() {
	docs.SwaggerInfo.BasePath = "/"

	args := os.Args
	if len(args) < 2 {
		fmt.Println("Loading default config")
		configuration = config.GetConfig(os.Getenv("HOME") + "/.yats.json")
	} else {
		instanceName = args[1]
		fmt.Printf("Loading instance: [%s] config", instanceName)
		configuration = config.GetConfig(os.Getenv("HOME") + "/.yats/" + instanceName + ".json")
	}

	db.Session = db.InitializeDb(configuration)

	if configuration.IsArchiveNode == "true" {
		fmt.Println("Starting Archive Node")
		go MaintenanceThread(configuration)
	}

	if configuration.GrpcAddress != "" {
		fmt.Printf("Starting GRPC Server on address: %s\n", configuration.GrpcAddress)
		go grpc.RunYatsGrpcServer(configuration.GrpcAddress)
	}

	fmt.Printf("Starting REST Server on address: %s\n", configuration.RestAddress)
	RestService(configuration)
}