Skip to content

Instantly share code, notes, and snippets.

@johnhof
Last active July 12, 2024 00:19
Show Gist options
  • 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-memory key/value store.

Parameters

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

Data Format

The Structured fields for an entity should be:

type Entity struct {
  Key        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 entity for Key

Delete: Remove an entity by Key

List: list entities with query modifiers:

  • Filtering:
    • Labels - any of the provided labels

Sample testing boilerplate

package main

type Entity struct {
 Key        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