gin

package
v2.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 4 Imported by: 0

README

Gin Server

Usage

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/go-kratos/kratos/v2"

	ginS "github.com/go-kratos-ecosystem/components/v2/gin"
)

func main() {
	gs := ginS.NewServer(
		gin.Default(),
		ginS.Addr(":8080"),
	)

	gs.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

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

	err := app.Run()
	if 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 added in v2.14.0

func Addr(addr string) Option

func Middleware added in v2.21.0

func Middleware(middlewares ...gin.HandlerFunc) Option

func WithAddr deprecated

func WithAddr(addr string) Option

Deprecated: use Addr

type Server

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

func NewServer

func NewServer(e *gin.Engine, opts ...Option) *Server

func (*Server) Start

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

func (*Server) Stop

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

Directories

Path Synopsis
middleware

Jump to

Keyboard shortcuts

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