Golang Concurrent Map

Kevin FOO
Sep 17, 2020

--

How to share a map or any other variable in a multi threaded environment in Go/Golang. For me, it happened very often in Gorilla Mux where I need temporary storage shared between requests but I do not want to store it in the database.

Code below is web clipboard.

To set a variable with value. Use curl or your browser’s address bar. Limitation to this version is that the value you are trying to assign must not have “/” slash in it.

curl 'http://127.0.0.1/set/YOUR_VARIABLE/YOUR_VALUE'

To retrieve a variable’s value

curl 'http://127.0.0.1/get/YOUR_VARIABLE'

To list all variables

curl 'http://127.0.0.1/list'

To delete a variable

curl 'http://127.0.0.1/del/YOUR_VARIABLE'

To clear all variables

curl 'http://127.0.0.1/clear'

I modified my own version from the above vanilla version and now it does not have the “/” slash limitation. View it at https://clipboard.oofnivek.com

< Back to all the stories I had written

--

--

Kevin FOO
Kevin FOO

Written by Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.