engine

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 1

README

AMWK Framework — Engine

AMWK Engine provides the kernel component for the AMWK framework. It provides the request/response handling, middleware workflow, and more. The engine is a part of the framework, and it is designed to be adapter-agnostic, allowing it to work with various runtime environments.

It is for internal use by adapter implementations, please check the Getting Started section to see how to use it in your adapter.

Requirements

  • Recommended Go version: 1.22 or newer.

You can add the packages to your module-enabled project:

go get github.com/go-amwk/core
go get github.com/go-amwk/engine

Getting Started

For adapter developers, you need to create your own adapter package base on your runtime environment, and provide your request and response implementations that implement the core.Request and core.Response interfaces.

It's a simple example to show how to use the engine package in your adapter's request handler:

package main

import (
  "github.com/go-amwk/engine"
  "github.com/go-amwk/core"
)

// Example handler invoked by your runtime environment for each incoming request
func (app *App) HandleRequest(req *YourRequest, res *YourResponse) {
  // create request context for the incoming request and response
  ctx := engine.NewContext(app, req, res)

  // run the handlers
  if err := ctx.Next(); err != nil {
    // handle error
  }

  // send response via your runtime-specific response object
  // e.g. res.Send()
}

Contributing

  • Fork and clone the repository.
  • Create a feature branch for your changes.
  • Implement changes and add tests.
  • Run tests and linters locally:
  • Push your branch and open a pull request.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

func NewContext

func NewContext(app core.Application, req core.Request, res core.Response) *Context

func (*Context) Abort

func (ctx *Context) Abort()

Abort marks the context as aborted, and subsequent handlers will not be executed.

func (*Context) AddHeader

func (ctx *Context) AddHeader(key, value string)

AddHeader adds a header to the response.

func (*Context) Application

func (ctx *Context) Application() core.Application

Application returns the application instance associated with the context.

func (*Context) Body

func (ctx *Context) Body() (io.ReadCloser, error)

Body returns the request body as a readable stream.

func (*Context) ClientIP

func (ctx *Context) ClientIP() string

ClientIP returns the IP address of the client making the request.

func (*Context) ContentLength

func (ctx *Context) ContentLength() int64

ContentLength returns the length of the request body in bytes.

func (*Context) ContentType

func (ctx *Context) ContentType() string

ContentType returns the Content-Type header of the request.

func (*Context) Context

func (ctx *Context) Context() context.Context

Context returns the Context associated with the request.

func (*Context) Cookie

func (ctx *Context) Cookie(name string) (*http.Cookie, error)

Cookie retrieves a cookie by name from the request.

func (*Context) Cookies

func (ctx *Context) Cookies() []*http.Cookie

Cookies returns all cookies from the request.

func (*Context) DelHeader

func (ctx *Context) DelHeader(key string)

DelHeader removes a header from the response.

func (*Context) Get

func (ctx *Context) Get(key string) (any, bool)

Get returns the value associated with the key in the context.

func (*Context) GetHeader

func (ctx *Context) GetHeader(key string) string

GetHeader retrieves a header value by name from the response.

func (*Context) Header

func (ctx *Context) Header(key string) string

Header retrieves a header value by name from the request.

func (*Context) HeaderValues

func (ctx *Context) HeaderValues(key string) []string

HeaderValues retrieves all values for a header by name from the request.

func (*Context) Headers

func (ctx *Context) Headers() http.Header

Headers returns all headers from the request.

func (*Context) IsAbort

func (ctx *Context) IsAbort() bool

IsAbort checks if the context is marked as aborted.

func (*Context) Method

func (ctx *Context) Method() string

Method returns the HTTP method of the request (e.g., GET, POST).

func (*Context) Next

func (ctx *Context) Next() error

Next calls the next handler in the handlers chain.

func (*Context) Path

func (ctx *Context) Path() string

Path returns the request path.

func (*Context) PathValue

func (ctx *Context) PathValue(name string) string

PathValue retrieves a path parameter value by name from the request.

func (*Context) Protocol

func (ctx *Context) Protocol() string

Protocol returns the HTTP protocol version of the request (e.g., HTTP/1.1).

func (*Context) Queries

func (ctx *Context) Queries() url.Values

Queries returns all query parameters from the request as a url.Values.

func (*Context) Query

func (ctx *Context) Query(key string) string

Query retrieves a query parameter value by name from the request.

func (*Context) QueryValues

func (ctx *Context) QueryValues(key string) []string

QueryValues retrieves all values for a query parameter by name from the request.

func (*Context) Request

func (ctx *Context) Request() core.Request

Request returns the wrapped Request object associated with the context.

func (*Context) Resource

func (ctx *Context) Resource() string

Resource returns the resource pattern of the request.

func (*Context) Response

func (ctx *Context) Response() core.Response

Response returns the wrapped Response object associated with the context.

func (*Context) Set

func (ctx *Context) Set(key string, value any) any

Set sets the value for the key in the context and returns the previous value.

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, value string)

SetHeader sets a header in the response.

func (*Context) Status

func (ctx *Context) Status(code int) error

Status sets the HTTP status code for the response and returns an error if it fails.

func (*Context) Use

func (ctx *Context) Use(handlers ...core.HandlerFunc)

Use adds handlers to the context, which will be executed in the order they are added.

func (*Context) Write

func (ctx *Context) Write(data []byte) (int, error)

Write writes data to the response body.

Jump to

Keyboard shortcuts

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