Giter VIP home page Giter VIP logo

x's Introduction

Darvaza Extra

Go Reference Go Report Card

darvaza.org/x hosts mid complexity packages with no big dependencies or assumptions.

Dependencies

The Darvaza Extra modules are built on top of a handful low(ish) level packages in addition to the Go Standard Library.

  • Our core package, darvaza.org/core, dealing with network addresses, worker groups, errors and lists among other simple helpers.
  • Our structured logger interface, darvaza.org/slog, allowing users to hook their favourite logger.
  • And our thin and simple LRU for local in-memory caching, darvaza.org/cache/x/simplelru.

Packages

Config

darvaza.org/x/config provides helpers for dealing with config files.

TLS

darvaza.org/x/tls provides helpers to work with tls connections and certificates.

Web

darvaza.org/x/web provides helpers for implementing http.Handlers.

See also

x's People

Contributors

amery avatar karasz avatar

Watchers

 avatar  avatar

x's Issues

Improve net/bind to use SO_REUSEPORT and friends

All the Listeners from the bind folder should have the option of being created with SO_REUSEPORT, so a Config should look like:

// Config is the configuration for Bind()
type Config struct {
.......
	Port uint16
	// PortStrict tells us not to try other ports
	PortStrict bool
	// PortAttempts indicates how many times we will try finding a port
	PortAttempts int
	// Defaultport indicates the port to try on the first attempt if Port is zero
	DefaultPort uint16
        // PortReuse indicates that the listener is able to reuse the port between threads/processes
        PortReuse bool

.....

	// ListenTCP is the helper to use to listen on TCP ports
	ListenTCP func(network string, laddr *net.TCPAddr) (*net.TCPListener, error)
	// ListenUDP is the helper to use to listen on UDP ports
	ListenUDP func(network string, laddr *net.UDPAddr) (*net.UDPConn, error)
.......
}

also default ListenTCP and ListenUDP should be created

var listenConfig = net.ListenConfig{
	Control: Control,
}

func ListenTCP(network, address string) (net.Listener, error) {
	return listenConfig.Listen(context.Background(), "tcp", address)
}
func ListenUDP(network, address string) (net.PacketConn, error) {
	return listenConfig.ListenPacket(context.Background(), "udp", address)
}

with Control function implemented for windows, linux, unix

example for unix:

import (
	"syscall"

	"golang.org/x/sys/unix"
)

func Control(network, address string, c syscall.RawConn) (err error) {
	controlErr := c.Control(func(fd uintptr) {
		err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
		if err != nil {
			return
		}
		err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
	})
	if controlErr != nil {
		err = controlErr
	}
	return
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.