server

package
v0.0.0-...-2c276d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>

Index

Constants

This section is empty.

Variables

View Source
var ServerCommand = &command.Command{
	Path:        []string{"server"},
	Summary:     "Runs the http server",
	Description: "",
	Options: command.Options{
		"config": {
			Type:    "string",
			Default: "./config.joao.yaml",
		},
		"db": {
			Type:    "string",
			Default: "./puerta.db",
		},
	},
	Action: func(cmd *command.Command) error {
		config := cmd.Options["config"].ToValue().(string)
		db := cmd.Options["db"].ToValue().(string)

		data, err := os.ReadFile(config)
		if err != nil {
			return fmt.Errorf("could not read config file: %w", err)
		}

		cfg := server.ConfigDefaults(db)

		if err := yaml.Unmarshal(data, &cfg); err != nil {
			return fmt.Errorf("could not unserialize yaml at %s: %w", config, err)
		}

		logger := logrus.New()
		logger.SetFormatter(&logrus.JSONFormatter{DisableTimestamp: false})

		router, err := server.Initialize(cfg)
		if err != nil {
			return err
		}

		logrus.Infof("Listening at %s", cfg.HTTP.Listen)
		return http.ListenAndServe(cfg.HTTP.Listen, router)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL