Documentation
¶
Overview ¶
Package ipieces allows users to create IP address-based Geocaching puzzles.
To create a puzzle, you need to populate a Puzzle struct and call Puzzle.Run on it. For example:
package main import ( "github.com/bitlux/caches/ipieces" "github.com/bitlux/vpnapi" ) func main() { p := ipieces.Puzzle{ Final: []ipieces.Digit{ ipieces.Digit{Value: "3", Status: ipieces.VISIBLE} ipieces.Digit{Value: "7", Status: ipieces.VISIBLE} ipieces.Digit{Value: "2", Status: ipieces.VISIBLE} ipieces.Digit{Value: "4", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} ipieces.Digit{Value: "1", Status: ipieces.VISIBLE} ipieces.Digit{Value: "2", Status: ipieces.VISIBLE} ipieces.Digit{Value: "2", Status: ipieces.VISIBLE} ipieces.Digit{Value: "0", Status: ipieces.VISIBLE} ipieces.Digit{Value: "4", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} ipieces.Digit{Value: "0", Status: ipieces.HIDDEN} }, IndexFunc: func(b [sha256.Size]byte) int { return int(b[sha256.Size-1]) % 8 }, // Setting Client is optional. Client: vpnapi.New("YOUR-API-KEY-HERE"), Backdoor: "topsecret", GCCode: "GCB2PKC", } p.Run() }
Puzzle.Run creates two handlers:
- a text endpoint at /text which responds with a short plaintext page with the client's IP, the computed index into the final coordinates, and the revealed coordinate, and
- a default endpoint, which serves any path other than /text, and responds with an HTML page.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Digit ¶
type Digit struct { // Value is a single digit, in string form. Value string // Status is how this digit should be displayed: visible, hidden, or revealed. Status Display }
A Digit is one of the digits that make up the coordinates of the final.
type Puzzle ¶
type Puzzle struct { // Final is the full final coordinates of the puzzle. Final []Digit // IndexFunc determines which digit of Final is revealed. The return value must be less than the number // of hidden Digits, because it is used as an index into the hidden Digits in Final. IndexFunc func([sha256.Size]byte) int // Client determines how to handle requests from IP addresses that belong to VPNs or proxies. // If Client is nil, no VPN checking will be done. In order to do VPN checking, first obtain an // API key from http://vpnapi.io. Pass that key to github.com/bitlux/vpnapi.Client.New to create // a *vpnapi.Client, and set Client to that value. Client VPNChecker // Backdoor allows you to test how the server handles a specific IP address. Backdoor will be accepted // as an HTTP header name. The server will read the header value as the client's IP address. For // example, if Backdoor is "geocache" and the server is running on localhost:8080, the following // command will tell the server that the request is coming from IP 1.2.3.4: // curl -H "geocache: 1.2.3.4" localhost:8080 // Any string is a valid . Backdoor string // GCCode is used to link back to the puzzle on geocaching.com. GCCode string // contains filtered or unexported fields }
type VPNChecker ¶
VPNChecker determines whether a client's IP address belongs to a VPN or proxy. Its concrete implementation is *github.com/bitlux/vpnapi.Client. In order to use vpnapi.Client, you must first obtain an API key from http://vpnapi.io.
Click to show internal directories.
Click to hide internal directories.