/**************************************************************************************
 *
 *     Project:    kvmstoreserver
 *     File name:  stage0_ext3.go
 *     Version:    1.0.0
 *     Date:       2018-01-14
 *
 *     Autor:      Bogdanovic Theodor
 *     Contact:    t.bogdanovic@hotmail.com
 *
 *     License:    GPLv3
 *
 **************************************************************************************/
/**************************************************************************************
 * Copyright 2018 Bogdanovic Theodor
 *
 * This file is part of kvmstoreserver.
 *
 * kvmstoreserver is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * kvmstoreserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with kvmstoreserver.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************************/
/**************************************************************************************
 *  Further explanations:  This source code is under the license specified by the
 *                         Autor above. Core components or other packages are still
 *                         in source code form, under the license specified by the
 *                         respective author.
 **************************************************************************************/

package main

import (
	"fmt"
	"net/http"
	"time"
	conf "utils/configMap"
)

//*****************************************************************************
//*
//*      Private Functions: Loader Functions
//*
//*****************************************************************************

// Here a new HTTP server instance is formed. It runs on its own structure, so
// that functionalities of the Go HTTP package can be abstracted using own
// methods
func initializeHTTPInstance() {

	httpFrontend.server = http.Server{
		Addr:              conf.GetStringOf("http_hostname") + ":" + conf.GetStringOf("http_port"),
		ReadHeaderTimeout: time.Second * time.Duration(conf.GetInt32Of("read_header_timeout")),
		ReadTimeout:       time.Second * time.Duration(conf.GetInt32Of("read_timeout")),
		WriteTimeout:      time.Second * time.Duration(conf.GetInt32Of("write_timeout")),
		IdleTimeout:       time.Millisecond * time.Duration(conf.GetInt32Of("tcp_idle_timeout_millsec")),
	}
}

//*****************************************************************************
//*
//*      Variable declarations
//*
//*****************************************************************************

var httpFrontend httpServer

//*****************************************************************************
//*
//*      Structure: httpServer
//*
//*****************************************************************************

// httpServer ...
type httpServer struct {
	server http.Server
}

//******************** Methods ************************************************

func (slf *httpServer) start() {

	err := slf.server.ListenAndServe()
	if err != nil {
		fmt.Println("The HTTP component is stopped")
	}
}

func (slf *httpServer) stop() { slf.server.Close() }
