votifier

package module
v0.0.0-...-2724a35 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 15 Imported by: 0

README

votifier

This is a simple, no-frills Votifier client and server written in Go. You can find usage examples under the examples directory.

go get go.minekube.com/votifier@latest

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// SendVote sends a vote through the client.
	SendVote(vote Vote) error
}

Client represents a Votifier client.

type Protocol

type Protocol int

Protocol represents a Votifier protocol.

const (
	V1 Protocol = iota + 1 // Uses base64 encoded RSA public key as token for vote verification.
	V2                     // Uses any token string for vote verification.
)

Protocols versions supported.

type ReceiverRecord

type ReceiverRecord struct {
	PrivateKey    *rsa.PrivateKey // v1
	TokenProvider TokenProvider   // v2
}

type Result

type Result struct {
	Status string
}

type Server

type Server struct {
	VoteHandler VoteListener // Required vote handler
	Records     []ReceiverRecord
	OnErr       func(net.Conn, error) // Optional connection handler
}

Server represents a Votifier server.

func (*Server) HandleConn

func (s *Server) HandleConn(c net.Conn) error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(address string) error

ListenAndServe binds to a specified address-port pair and starts serving Votifier requests.

func (*Server) Serve

func (s *Server) Serve(ln net.Listener) error

Serve serves requests on the provided listener.

type TokenProvider

type TokenProvider interface {
	// Token returns the token for a service.
	Token(service string) string
}

TokenProvider provides a token for a given vote service. The vote service is the name of the service the user is voting from and sent by the vote service itself (e.g. "minecraft-serverlist.net").

func StaticTokenProvider

func StaticTokenProvider(token string) TokenProvider

StaticTokenProvider returns the same token for every request.

type TokenProviderFunc

type TokenProviderFunc func(service string) string

TokenProviderFunc is a function that implements TokenProvider.

func (TokenProviderFunc) Token

func (f TokenProviderFunc) Token(service string) string

Token implements TokenProvider.

type V1Client

type V1Client struct {
	// contains filtered or unexported fields
}

V1Client represents a Votifier v1 client.

func NewV1Client

func NewV1Client(address string, publicKey *rsa.PublicKey) *V1Client

NewV1Client creates a new Votifier client.

func (*V1Client) SendVote

func (client *V1Client) SendVote(vote Vote) error

SendVote sends a vote through the client.

type V2Client

type V2Client struct {
	// contains filtered or unexported fields
}

V2Client represents a Votifier v2 client.

func NewV2Client

func NewV2Client(address string, token string) *V2Client

NewV2Client creates a new Votifier v2 client.

func (*V2Client) SendVote

func (client *V2Client) SendVote(vote Vote) error

SendVote sends a vote through the client.

type Vote

type Vote struct {
	// The name of the service the user is voting from.
	ServiceName string `json:"serviceName"`

	// The user's Minecraft username.
	Username string `json:"username"`

	// The voting user's IP address.
	Address string `json:"address"`

	// The timestamp this vote was issued.
	Timestamp time.Time `json:"timeStamp"`
}

Vote represents a Votifier vote.

func (*Vote) DecodeV1

func (v *Vote) DecodeV1(data []byte, key *rsa.PrivateKey) error

DecodeV1 decodes the vote from the V1 protocol.

func (*Vote) DecodeV2

func (v *Vote) DecodeV2(data []byte, tokenProvider TokenProvider, challenge string) error

func (*Vote) EncodeV1

func (v *Vote) EncodeV1(publicKey *rsa.PublicKey) (*[]byte, error)

EncodeV1 encodes the vote to the V1 protocol.

func (*Vote) EncodeV2

func (v *Vote) EncodeV2(token string, challenge string) ([]byte, error)

type VoteListener

type VoteListener func(*Vote, Protocol, net.Conn) error

VoteListener takes a vote and an int describing the protocol version (1 or 2).

Directories

Path Synopsis
examples
client command
server command

Jump to

Keyboard shortcuts

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