server

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias added in v1.0.3

type Alias Message

Alias is just an alias to handle embedded pointers

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

HTTPServer encapsulates HTTP server API.

func NewHTTPServer

func NewHTTPServer(addr string, maxMessages int, logger *log.Logger) *HTTPServer

NewHTTPServer creates new HTTP server.

func (*HTTPServer) AddMessage

func (h *HTTPServer) AddMessage(message *Message)

AddMessage prepends message to the slice.

func (*HTTPServer) HandleLog

func (h *HTTPServer) HandleLog(w http.ResponseWriter, r *http.Request)

HandleLog replies with messages taken from UDP.

func (*HTTPServer) Serve

func (h *HTTPServer) Serve()

Serve starts serving requests.

func (*HTTPServer) Shutdown

func (h *HTTPServer) Shutdown()

Shutdown stops http listener.

type Message

type Message struct {
	IP      string    `json:"ip"`
	Payload string    `json:"payload"`
	Time    time.Time `json:"time"`
}

Message is a struct that is created from UDP and served through HTTP.

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler interface to reformat time to human readable format.

type UDPServer

type UDPServer struct {
	// contains filtered or unexported fields
}

UDPServer encapsulates UDP server API.

func NewUDPServer

func NewUDPServer(addr string, logger *log.Logger) *UDPServer

NewUDPServer creates new UDP server.

func (*UDPServer) ReadMessage

func (u *UDPServer) ReadMessage(bufferSize int) (*Message, error)

ReadMessage reads bytes from UDP and serializes them into Message struct.

func (*UDPServer) Shutdown

func (u *UDPServer) Shutdown()

Shutdown closes UDP listener.

Jump to

Keyboard shortcuts

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