chi

package
v2.26.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 4 Imported by: 0

README

go-chi server

Example

package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-kratos/kratos/v2"

	chis "github.com/go-kratos-ecosystem/components/v2/chi"
)

func main() {
	cs := chis.NewServer(
		chi.NewRouter(),
		chis.Addr(":8001"),
	)

	cs.Get("/", func(w http.ResponseWriter, _ *http.Request) {
		_, _ = w.Write([]byte("hello world"))
	})

	app := kratos.New(
		kratos.Server(cs),
	)

	if err := app.Run(); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

func Addr

func Addr(addr string) Option

type Server

type Server struct {
	*chi.Mux
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c *chi.Mux, opts ...Option) *Server

func (*Server) Start

func (s *Server) Start(_ context.Context) error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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