Go to file
kingecg f86fa0112e remove debug log 2023-12-15 21:46:06 +08:00
.vscode fix REST api 2023-12-13 21:09:01 +08:00
admin make proxy yse directive and forbidden get/set admin by api 2023-12-14 23:47:04 +08:00
adminui fix normalize bug 2023-12-13 10:59:47 +08:00
hander make proxy yse directive and forbidden get/set admin by api 2023-12-14 23:47:04 +08:00
model fix directive 2023-12-15 21:45:04 +08:00
public fix file handler and update logger 2023-12-10 01:08:39 +08:00
server fix directive 2023-12-15 21:45:04 +08:00
utils add api 2023-12-13 17:59:14 +08:00
vendor add daemon 2023-12-10 19:26:09 +08:00
.gitignore Initial commit 2023-12-06 20:58:08 +08:00
LICENSE Initial commit 2023-12-06 20:58:08 +08:00
Makefile fix normalize bug 2023-12-13 10:59:47 +08:00
README.md add api 2023-12-13 17:59:14 +08:00
config.json fix directive 2023-12-15 21:45:04 +08:00
go.mod add daemon 2023-12-10 19:26:09 +08:00
go.sum add daemon 2023-12-10 19:26:09 +08:00
gohttp.go make proxy yse directive and forbidden get/set admin by api 2023-12-14 23:47:04 +08:00
main.go add api 2023-12-13 17:59:14 +08:00

README.md

gohttp

目标

实现一个类似nginx功能的http服务器

功能

  • 支持静态文件
  • Proxy
  • 支持rewrite
  • 支持TLS
  • 支持端口复用

配置

{
   "logging" :{
        "appenders": {
            "out" :{
                "type": "file",
                "options":{
                    "file": "gohttpd.log"
                }
            }
        },
        "categories": {
            "default": {
                "appenders": [ "out" ],
                "level": "debug"
            }
        }
    },
    "admin" : {
        "name": "admin",
        "port" : 8088,
        "username": "admin",
        "password": "admin",
        "paths": [
            {
                "path": "/",
                "root": "./adminui",
                "default": "index.html"
            }
        ]
    },
    "servers":[{
        "port" : 8080,
        "name":"test",
        "paths":[
            {
                "path": "/",
                "root": "/home/kingecg/code/gohttp/public/",
                "default": "index.html"
            },
            {
                "path": "/ws",
                "upstreams":["http://localhost:3000"],
                "pathrewrite": {
                    "replace": "/ws",
                    "with": "/"
                }
            }
        ]
    }] 
}
  • logging 日志配置
  • admin 管理后台配置
  • servers 服务器配置

日志采用自己实现的类log4j库目前只支持console 和file两种appeder

servers 配置

  • port 端口
  • name 服务器名称
  • paths 路径配置
  • certfile 证书文件
  • keyfile 证书密钥文件

paths 配置

  • path 路径
  • root 根目录
  • default 默认文件
  • upstreams 代理地址
  • pathrewrite 路径重写

Packages

Server

RestMux 提供

  • Restful API注册功能的 ServerMux
  • Route
  • Url路径参数解析(形如:/user/:id)
  • 中间件
  • server管理

model

提供模型定义

admin

管理后台api

handler

目录 hander

提供文件和代理两种handler 其中proxy handler 提供简单的负载均衡和会话粘滞功能

构建

make clean && make build

在target目录下生成可执行文件

运行

./gohttpd