votifier

package module
v0.0.0-...-aa0f522 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2019 License: MIT Imports: 17 Imported by: 1

README

go-votifier

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

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 ReceiverRecord

type ReceiverRecord struct {
	PrivateKey *rsa.PrivateKey        // v1
	TokenId    ServiceTokenIdentifier // v2
	Metadata   interface{}
}

type Server

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

Server represents a Votifier server.

func NewServer

func NewServer(voteHandler VoteListener, records []ReceiverRecord) Server

NewServer creates a new Votifier server.

func (*Server) ListenAndServe

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

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

func (*Server) Serve

func (server *Server) Serve(l net.Listener) error

Serve serves requests on the provided listener.

type ServiceTokenIdentifier

type ServiceTokenIdentifier func(string) string

ServiceTokenIdentifier defines a function for identifying a token for a service.

func StaticServiceTokenIdentifier

func StaticServiceTokenIdentifier(token string) ServiceTokenIdentifier

StaticServiceTokenIdentifier returns a ServiceTokenIdentifier that returns a static token for any service.

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 string `json:"timeStamp"`
}

Vote represents a Votifier vote.

func NewVote

func NewVote(serviceName string, username string, address string) Vote

NewVote creates a new vote and pre-fills the timestamp.

type VoteListener

type VoteListener func(Vote, VotifierProtocol, interface{})

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

type VotifierProtocol

type VotifierProtocol int
const (
	VotifierV1 VotifierProtocol = iota
	VotifierV2 VotifierProtocol = iota
)

Jump to

Keyboard shortcuts

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