lottery

package module
v0.0.0-...-61949d9 Latest Latest
Warning

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

Go to latest
Published: May 20, 2018 License: MIT Imports: 4 Imported by: 0

README

lottery

Golang lottery library.

Install

$ go get github.com/sachaos/lottery

Usage

Prepare Weighter interface and pass to lottery.Draw()

package main

import (
	"fmt"

	"github.com/sachaos/lottery"
)

type Item struct {
	Name   string
	weight int
}

func (i Item) Weight() int {
	return i.weight
}

func main() {
	l := lottery.NewDefaultLottery()
	items := []lottery.Weighter{
		&Item{Name: "high rare item", weight: 10},
		&Item{Name: "rare item", weight: 100},
		&Item{Name: "normal item", weight: 1000},
	}
	idx := l.Draw(items)
	fmt.Printf("You got %s!\n", items[idx].(*Item).Name)
}

Documentation

Overview

Package lottery is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lottery

type Lottery interface {
	Draw([]Weighter) int
}

func NewDefaultLottery

func NewDefaultLottery() Lottery

type MockLottery

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

MockLottery is a mock of Lottery interface

func NewMockLottery

func NewMockLottery(ctrl *gomock.Controller) *MockLottery

NewMockLottery creates a new mock instance

func (*MockLottery) Draw

func (m *MockLottery) Draw(arg0 []Weighter) int

Draw mocks base method

func (*MockLottery) EXPECT

func (m *MockLottery) EXPECT() *MockLotteryMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

type MockLotteryMockRecorder

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

MockLotteryMockRecorder is the mock recorder for MockLottery

func (*MockLotteryMockRecorder) Draw

func (mr *MockLotteryMockRecorder) Draw(arg0 interface{}) *gomock.Call

Draw indicates an expected call of Draw

type MockWeighter

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

MockWeighter is a mock of Weighter interface

func NewMockWeighter

func NewMockWeighter(ctrl *gomock.Controller) *MockWeighter

NewMockWeighter creates a new mock instance

func (*MockWeighter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockWeighter) Weight

func (m *MockWeighter) Weight() int

Weight mocks base method

type MockWeighterMockRecorder

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

MockWeighterMockRecorder is the mock recorder for MockWeighter

func (*MockWeighterMockRecorder) Weight

func (mr *MockWeighterMockRecorder) Weight() *gomock.Call

Weight indicates an expected call of Weight

type Weighter

type Weighter interface {
	Weight() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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