Skip to content

Instantly share code, notes, and snippets.

@johnhof
Last active April 18, 2024 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhof/b5523bf110b6541f0250f523e5feec37 to your computer and use it in GitHub Desktop.
Save johnhof/b5523bf110b6541f0250f523e5feec37 to your computer and use it in GitHub Desktop.

Prompt

Create a golang in-momory key/value store.

Parameters

Any coding tools, googling, etc are allowed. Best practices can be skipped as long as theyre called out when they occur.

Data Format

The Structured fields for an object should be:

type Entry struct {
  ID        string
  CreatedAt time.Time
  Labels    []string
  Data    any
}

The data storage mechanism should be an in-memory data structure defined in your code.

Operations

Create: Add an entry for ID

Delete: Remove an entry by ID

List: list entries with query modifiers:

  • Filtering:
    • Labels - any of the provided labels

Sample testing boilerplate

package main

type Entry struct {
 ID        string
 CreatedAt time.Time
 Labels    []string
 Data      any
}


func main () {

 // Add A with labels [1]

 // Add B with labels [1,2]

 // Add C with labels [3]
  
 // List - returns all 3
  
 // List with labels [1] - returns A, B
  
 // List with labels [2] returns B
  
 // List with labels [2,3] returns B, C
  
 // Delete A
  
 // List - returns B, C

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment