ipieces

package
v0.0.0-...-c835fb6 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: Unlicense Imports: 12 Imported by: 0

README

ipieces

ipieces is a Go package used to create Geocaching puzzles such as GCB1ZXB.

Documentation

Available at https://pkg.go.dev/github.com/bitlux/caches/ipieces.

Deployment instructions

I deploy on Google Cloud Run. https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-go-service is a good reference on how to us Google Cloud Run.

Create a directory for your project and put your code in a file named main.go. Run go mod init <module name> to create a module (because your main.go imports packages outside the standard library, Google Cloud Run requires it to be in its own module).

To deploy, cd to the directory with your main.go file and run:

gcloud run deploy --source . <service> [--allow-unauthenticated]

where <service> is any name you want.

Testing

To set the IP address of the request to foo, use:

curl -H "<backdoor>: foo" localhost:8080/text

where <backdoor> is the Puzzle.Backdoor string you set.

Contact / Support

I welcome issues and pull requests on GitHub and messages and email on geocaching.com.

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 Display

type Display int

Display controls how a Digit is displayed.

const (
	// Visible by default
	VISIBLE Display = iota
	// Hidden by default
	HIDDEN
	// Hidden by default, revealed in this rendering
	REVEALED
)

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
}

func (Puzzle) Run

func (p Puzzle) Run()

Runs starts an HTTP server and blocks forever (or until a fatal error occurs).

type VPNChecker

type VPNChecker interface {
	Query(string) (*vpnapi.Response, error)
}

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.

Jump to

Keyboard shortcuts

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