server

package module
v0.0.0-...-aca0c44 Latest Latest
Warning

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

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

README

GoGonet: A Lightweight HTTP Server in Go 🚀

Welcome to GoGonet! A simple, yet powerful lightweight HTTP server written in Go. Whether you're prototyping or developing a minimal application, GoGonet is here to make your development smoother.

🌟 Features

  • 🚀 Fast server initialization
  • 🛣️ Dynamic URL routing with path and query parameters
  • 🧵 Multithreaded request handling
  • 🛡️ Buffer overflow protection with max queued requests

🚀 Getting Started

🔧 Prerequisites
  • Go (>= 1.15)
📦 Installation
  1. Fetch the Go package:
$ go get github.com/Ashfakh/gogonet
  1. Import the package in your Go code:
$ import server "github.com/Ashfakh/gogonet"
💼 Basic Usage
  1. Initialize a server instance:
serv := server.Server("0.0.0.0", 8080, 1, 10) // host, port, numHandlers, maxQueued
  1. Define routes and associated request handlers:
serv.Route(server.GET, "/", requestHandlerFunc)
  1. Fire up the server! 🚀
serv.Run()
🖋️ Sample Request Handler
func request(req server.Request) server.Response {
    if req.Params()["name"] != "" {
        return server.NewResponse(200, "Hello "+req.Params()["name"]+" 🖐️")
    }
    return server.NewResponse(200, "Hello World 🌍")
}

📑 Files Overview

  • server.go 🔧 - Contains the primary server code, including structures and methods required for setting up and running the HTTP server.

  • httpHandler.go 💌 - Takes charge of parsing the incoming requests and routing them to the appropriate request handlers.

  • The Implementation block is a practical example of how to wield this server library in a Go application.

👤 Author

Ashfakh

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Method

type Method int
const (
	GET Method = iota
	POST
	PUT
	DELETE
)

func (Method) String

func (m Method) String() string

type Request

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

func (*Request) HTTPVersion

func (rq *Request) HTTPVersion() string

func (*Request) Headers

func (rq *Request) Headers() map[string]string

func (*Request) Method

func (rq *Request) Method() string

func (*Request) Params

func (rq *Request) Params() map[string]string

func (*Request) Path

func (rq *Request) Path() string

type RequestError

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

func (*RequestError) Error

func (err *RequestError) Error() string

func (*RequestError) ErrorCode

func (err *RequestError) ErrorCode() int

type Response

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

func NewResponse

func NewResponse(statusCode int, body string) Response

func (*Response) AddHeader

func (res *Response) AddHeader(key, val string)

func (*Response) SetBody

func (res *Response) SetBody(body string)

func (*Response) SetStatusCode

func (res *Response) SetStatusCode(code int)

type ServerObj

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

func Server

func Server(host string, port int, numHandlers int, maxQueued int) ServerObj

func (*ServerObj) Route

func (s *ServerObj) Route(method Method, path string, f func(Request) Response)

func (*ServerObj) Run

func (s *ServerObj) Run() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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