whs

package module
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

web http(s) service
markdown »

Demo · Bug · Issues

English | 中文

Guide

  1. create server
s := New("127.0.0.1", 80)
  1. routes
s.RegisterRouter("/user", func(c *Context) {
c.ResponseWriter.Write([]byte("/user"))
}
  1. route group
home := s.Group("/home")
{
    home.RegisterRouter("/index", func(c *Context) { c.ResponseWriter.Write([]byte("/home/index")) })
}}
)
  1. middleware
home.UseMiddleware(func(c *Context) {
c.ResponseWriter.Write([]byte("2"))
c.Next()
c.ResponseWriter.Write([]byte("2"))
})
  1. template
s.Static("static/", "/static")
s.Func(template.FuncMap{"FormatTime": FormatTime})
s.Template("template/*")```
6. start and stop 
```text
s.Start()
s.stop()
Pre development Configuration Requirements
  1. go version 1.21.1
Installation
  1. go get github.com/learnselfs/wlog github.com/learnselfs/wlog

Contributor

Please read CONTABUTING.md to find out the developers who have contributed to this project.

Open Source Projects

Contributing makes the open source community an excellent place to learn, motivate, and create. Any contribution you make is greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project has signed an Apache license, please refer to for details. LICENSE

Thanks

Documentation

Overview

Package whs @Author Bing @Date 2024/2/27 10:44:00 @Desc

Package whs @Author Bing @Date 2024/2/3 21:01:00 @Desc

Package whs @Author Bing @Date 2024/2/3 20:11:00 @Desc

Package whs @Author Bing @Date 2024/2/2 17:07:00 @Desc

Package whs @Author Bing @Date 2024/2/4 20:58:00 @Desc

Package whs @Author Bing @Date 2024/2/3 20:37:00 @Desc

Package whs @Author Bing @Date 2024/2/3 20:11:00 @Desc

Package whs @Author Bing @Date 2024/2/10 20:46:00 @Desc

Package whs @Author Bing @Date 2024/2/3 22:00:00 @Desc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler added in v1.5.8

func ErrorHandler(c *Context, status int, err error)

func NotFoundHandler added in v1.2.0

func NotFoundHandler(c *Context)

Types

type Context added in v1.4.0

type Context struct {
	// request
	*http.Request

	// response
	http.ResponseWriter
	// contains filtered or unexported fields
}

Context for encapsulating request data and processing responses

func NewContent

func NewContent(r *http.Request, w http.ResponseWriter) *Context

NewContent returns a new Context

func (*Context) Html added in v1.4.0

func (c *Context) Html(state int, tmpl string, data map[string]any)

func (*Context) Json added in v1.4.0

func (c *Context) Json(state int, data any, msg string)

func (*Context) Next added in v1.4.0

func (c *Context) Next()

Next complete middleware

type Handler

type Handler func(ctx *Context)

type IRoute

type IRoute interface {
}

IRoute interface

type IService

type IService interface {
}

IService interface:

type Message added in v1.5.8

type Message struct {
	Code int    `json:"code"`
	Data any    `json:"data"`
	Msg  string `json:"msg"`
}

type Route added in v1.3.0

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

Route struct

func (*Route) DELETE added in v1.5.8

func (r *Route) DELETE(url string, handler Handler)

func (*Route) GET added in v1.5.8

func (r *Route) GET(url string, handler Handler)

func (*Route) Group added in v1.3.0

func (r *Route) Group(prefix string) *Route

Group route

func (*Route) POST added in v1.5.8

func (r *Route) POST(url string, handler Handler)

func (*Route) PUT added in v1.5.8

func (r *Route) PUT(url string, handler Handler)

func (*Route) RegisterRouter added in v1.3.0

func (r *Route) RegisterRouter(method, url string, handler Handler)

RegisterRouter for add router

func (*Route) Router added in v1.3.0

func (r *Route) Router(method, url string) *Route

func (*Route) UseMiddleware added in v1.4.0

func (r *Route) UseMiddleware(middleware Handler)

UseMiddleware complete

type Service

type Service struct {
	*Route
	*http.Server
	// contains filtered or unexported fields
}

Service struct

func New

func New(host string, port int) *Service

New function return http server

func (*Service) Func added in v1.5.1

func (s *Service) Func(fun template.FuncMap)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP for main processing function

func (*Service) Start

func (s *Service) Start()

Start for http server

func (*Service) Static added in v1.4.0

func (s *Service) Static(url, path string)

func (*Service) Stop

func (s *Service) Stop()

Stop for http server

func (*Service) Template added in v1.5.1

func (s *Service) Template(webPah string)

func (*Service) TemplateDelim added in v1.5.7

func (s *Service) TemplateDelim(left, right, webPah string)

Jump to

Keyboard shortcuts

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