http

package module
v0.0.0-...-7bce696 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 10 Imported by: 0

README

Clone of http.ListenAndServe

Exercise of syscall and async I/O

Usage

Start Server
$ cd internal/example
$ cat main.go
package main

import (
        "fmt"

        "github.com/arailly/go-http-clone"
)

func main() {
        http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                w.Write([]byte("Hello World\n"))
        })
        fmt.Println(http.ListenAndServe(":8080", nil))
}

$ go run main.go

Test
$ curl -i localhost:8080
HTTP/1.1 200
Content-Length: 11

Hello World

Features

  1. Use syscall instead of net or net/http package
  2. Asynchronous I/O with epoll

Limitations

  • GET only
    • other methods and request body is not available :)
  • Headers are not available.
  • Although I/O will not be blocked, user-defined handler will be blocked when accessed simultaneously.

Documentation

Index

Constants

View Source
const (
	StatusOK = 200
)

Variables

This section is empty.

Functions

func HandleFunc

func HandleFunc(pattern string, handler func(ResponseWriter, *Request))

func ListenAndServe

func ListenAndServe(addr string, handler Handler) error

Types

type Handler

type Handler interface {
	ServeHTTP(ResponseWriter, *Request)
}
type Header map[string][]string

type Request

type Request struct {
	Method string // only GET available
	// contains filtered or unexported fields
}

TODO: Method, URL, Proto, Header, Body

type ResponseWriter

type ResponseWriter interface {
	Write([]byte) (int, error)
	WriteHeader(statusCode int)
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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