config: server host and port

This commit is contained in:
Anirudh Oppiliappan 2022-12-12 22:58:23 +05:30
parent 60e1092dbc
commit 462c7ddc70
No known key found for this signature in database
GPG Key ID: 8A93F96F78C5D4C4
3 changed files with 11 additions and 1 deletions

View File

@ -10,3 +10,6 @@ template:
meta: meta:
title: git good title: git good
description: i think it's a skill issue description: i think it's a skill issue
server:
host: 127.0.0.1
port: 5555

View File

@ -19,6 +19,10 @@ type Config struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Description string `yaml:"description"` Description string `yaml:"description"`
} `yaml:"meta"` } `yaml:"meta"`
Server struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"server"`
} }
func Read(f string) (*Config, error) { func Read(f string) (*Config, error) {

View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
@ -20,5 +21,7 @@ func main() {
} }
mux := routes.Handlers(c) mux := routes.Handlers(c)
log.Fatal(http.ListenAndServe(":5555", mux)) addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
log.Println("starting server on", addr)
log.Fatal(http.ListenAndServe(addr, mux))
} }