webServer

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

🚀 WebServer: High-Performance Router

Go Version License

A lightweight, blazing-fast HTTP multiplexer for Go, built on a custom Trie (Prefix Tree) data structure. Designed for developers who want the power of a modern framework without the "bloat."


✨ Features

  • ⚡ Trie-Based Routing: O(n) lookup time where n is the number of path segments.
  • 🎭 Dynamic Parameters: Support for :id style segments (e.g., /users/:id/profile).
  • 🌐 Catch-All Wildcards: Use * to capture entire sub-paths—perfect for static file servers.
  • 📂 Static Asset Excellence: Built-in ServeFileSystem with automatic directory listing.
  • 🧹 Zero Dependencies: Only uses the Go standard library.

🛠️ Quick Start

1. Installation
go get [github.com/zuadi/webServer](https://github.com/zuadi/webServer)
2. Basic Usage (RESTful Example)
package main

import (
    "net/http"
    "webServer/router"
)

func main() {
    ws := router.NewRouter()

    // GET Request
    ws.Get("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Welcome to the Trie! 🌳"))
    })

    // POST Request (REST API)
    ws.Post("/api/data", func(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusCreated)
        w.Write([]byte(`{"status": "success"}`))
    })

    // Serve Static Files with Wildcards
    // This correctly strips the prefix and handles directory listings!
    ws.ServeFileSystem("/assets/*", "./static")

    http.ListenAndServe(":4040", ws)
}

📂 Route Matching Priority

GopherTrie uses a specific priority system to ensure the most logical route wins:

  1. Exact Match: /users/profile always beats a parameter.

  2. Parameter Match: /users/:id captures single segments.

  3. Wildcard Match: /static/* captures everything remaining if no other match is found.

Note: Directory listings are supported on /folder/* paths by correctly handling the trailing slash logic within the Trie.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WebServer

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

func NewWebServer

func NewWebServer(ip string, port int) *WebServer

func (*WebServer) Delete added in v0.0.15

func (s *WebServer) Delete(path string, handler models.HandlerFunc)

func (*WebServer) Get

func (s *WebServer) Get(path string, handler models.HandlerFunc)

func (*WebServer) ListenHttp

func (s *WebServer) ListenHttp() error

func (*WebServer) NewBroker added in v0.0.17

func (s *WebServer) NewBroker(path string, address string, brokerPort, wsPort int) (*models.Broker, error)

func (*WebServer) NewGroup added in v0.3.0

func (s *WebServer) NewGroup(path string) *models.Group

func (*WebServer) NewWebSocket added in v0.0.16

func (s *WebServer) NewWebSocket(path string) *models.WSClient

func (*WebServer) Post

func (s *WebServer) Post(path string, handler models.HandlerFunc)

func (*WebServer) Put added in v0.0.15

func (s *WebServer) Put(path string, handler models.HandlerFunc)

func (*WebServer) ServeFile

func (s *WebServer) ServeFile(path, file string)

func (*WebServer) ServeFileSystem

func (s *WebServer) ServeFileSystem(path, file string)

func (*WebServer) SetDefaultCORS added in v0.0.6

func (s *WebServer) SetDefaultCORS()

func (*WebServer) SetLogLevel added in v0.0.11

func (s *WebServer) SetLogLevel(level logger.Level)

func (*WebServer) Update added in v0.0.15

func (s *WebServer) Update(path string, handler models.HandlerFunc)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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