conn

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

README

package conn

package conn manages connection pool for client side application.

Usage:

import "github.com/hetianyi/gox/conn"

server := &conn.Server{
    Host: "127.0.0.1",
    Port: 8899,
}
conn.InitServerSettings(server, 100)
c, err := conn.GetConnection(server)
// ...

Documentation

Overview

Copyright (C) 2019 tisnyo <tisnyo@gmail.com>.

conn is connection pool designed for limiting the size of connections to server. license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConnection

func GetConnection(server Server) (*net.Conn, interface{}, error)

GetConnection tries to get a connection from it's connection pool.

func InitServerSettings

func InitServerSettings(server Server, maxConn uint, connMaxIdleTime time.Duration)

InitServerSettings initializes settings of a server. It is better way that initialize a server settings before getting connections from it's pool.

func NewPool

func NewPool(size uint, connFactory *ConnectionFactory) *pool

NewPool creates a connection pool.

func ReturnConnection

func ReturnConnection(server Server, conn *net.Conn, attr interface{}, broken bool)

ReturnConnection returns connection to it's connection pool.

func SetDefaultMaxConnIdleTime

func SetDefaultMaxConnIdleTime(connMaxIdleTime time.Duration)

SetDefaultMaxConnIdleTime sets default max connection expire time.

func SetDefaultMaxConnSize

func SetDefaultMaxConnSize(maxConn uint)

SetDefaultMaxConnSize sets default max connection size.

Types

type ConnectionFactory

type ConnectionFactory struct {
	Server          Server
	ConnMaxIdleTime time.Duration
	DialogTimeout   time.Duration
}

ConnectionFactory is a factory which creates connection for specific server。

type PlainServer

type PlainServer struct {
	Host string `json:"host"`
	Port uint16 `json:"port"`
}

func (*PlainServer) ConnectionString

func (ps *PlainServer) ConnectionString() string

GetConnectionString gets the server's connection string.

func (*PlainServer) GetHost

func (ps *PlainServer) GetHost() string

GetHost returns server's host.

func (*PlainServer) GetPort

func (ps *PlainServer) GetPort() uint16

GetPort returns server's port.

type Server

type Server interface {
	ConnectionString() string
	GetHost() string
	GetPort() uint16
}

Server defines a server connection info.

Jump to

Keyboard shortcuts

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