Skip to content

A lightweight and flexible web framework for Go, inspired by Express.js.

Notifications You must be signed in to change notification settings

mikaeloduh/Express.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express.go

A lightweight and flexible web framework for Go, inspired by Express.js. Express.go provides a robust set of features for building web applications and APIs with an elegant and intuitive interface.

Features

  • Middleware Support: Flexible middleware system for request/response handling
  • Routing: Simple and intuitive routing system
  • Error Handling: Built-in error handling middleware
  • Body Parsing: Support for JSON and XML request/response parsing
  • Dependency Injection: Built-in dependency injection container with different scopes
  • Rate Limiting: Built-in rate limiting middleware
  • Extensible: Easy to extend with custom middleware and handlers

Installation

go get webframework

Quick Start

package main

import "webframework/framework"

func main() {
    router := framework.NewRouter()
    
    // Add middleware
    router.Use(framework.JSONBodyParser)
    
    // Define routes
    router.Handle("/", "GET", func(w *framework.ResponseWriter, r *framework.Request) error {
        return w.Encode(map[string]string{"message": "Hello, World!"})
    })
    
    // Start server
    http.ListenAndServe(":3000", router)
}

Documentation

Router

The router is the core of Express.go. It handles HTTP requests and routes them to the appropriate handlers.

router := framework.NewRouter()
router.Handle("/path", "GET", handlerFunc)

Middleware

Middleware functions can be used to modify requests/responses and perform actions before/after handlers:

router.Use(framework.JSONBodyParser)
router.Use(YourCustomMiddleware)

Error Handling

Express.go provides built-in error handling:

router.RegisterErrorHandler(framework.DefaultNotFoundErrorHandler)
router.RegisterErrorHandler(framework.DefaultMethodNotAllowedErrorHandler)

Dependency Injection

The framework includes a dependency injection container with support for different scopes:

  • Singleton
  • Prototype
  • Request
container := framework.NewContainer()
container.Register("service", factory, framework.SingletonScopeStrategy{})

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lightweight and flexible web framework for Go, inspired by Express.js.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published