DavyJ0nes / go-generic-web-handler

exploring boundaries of Go Generics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Generic Web Handler

This is an exploration of how Go type parameters, introduced in Go 1.18, can be used with an HTTP handler as well as in table test cases where the input can be generic.

None of this is intended to be a best practice or even a good idea but purely as an experiment to see how to use type parameters for generic programming.

For more information on generic programming with Go see:

Structure

This example includes a simple server that handles summing slices of float64 or int from a POST request. The code for this can be found in server.

In client there is a client that makes a couple of requests with floats and ints to easily verify the server and be able to experiment with type parameters from both server and client side.

I've added comments in both packages with some oddities and where I've found boundaries with what Go Generics can be used at the moment.

Running

There is a Makefile to make running the experiment and its tests.

  • make run - Run main.go
  • make test - Run the tests for server and client packages.

About

exploring boundaries of Go Generics


Languages

Language:Go 93.8%Language:Makefile 6.2%