server

package
v2.27.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 4 Imported by: 0

README

HTTP Server

A common HTTP service component that supports Kratos Server.

Usage Example

package server_test

import (
	"net/http"

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

	"github.com/go-kratos-ecosystem/components/v2/http/server"
)

func Example() {
	srv := server.New(&http.Server{
		Addr: ":8080",
		Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.WriteHeader(http.StatusOK)
			_, _ = w.Write([]byte("hello world"))
		}),
	})

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

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

Documentation

Overview

Example
srv := server.New(&http.Server{
	Addr: ":8080",
	Handler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte("hello world"))
	}),
})

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

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPServerOption

type HTTPServerOption func(*http.Server)

func WithHTTPServerAddr

func WithHTTPServerAddr(addr string) HTTPServerOption

type Option

type Option func(*Server)

func WithName

func WithName(name string) Option

type Server

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

func New

func New(srv *http.Server, opts ...Option) *Server

func NewWithHandler

func NewWithHandler(handler http.Handler, opts ...HTTPServerOption) *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
JackTT - Gopher 🇻🇳