File: main.go

package info (click to toggle)
golang-github-francoispqt-gojay 1.2.13-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 86
file content (42 lines) | stat: -rw-r--r-- 803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main

import (
	"encoding/json"
	"log"
	"net/http"
)

func main() {
	log.Println("Listening on port 3000")
	log.Fatal(http.ListenAndServe(":3000", http.HandlerFunc(handler)))
}

func handler(w http.ResponseWriter, r *http.Request) {
	var body Body
	err := json.NewDecoder(r.Body).Decode(&body)
	if err != nil {
		panic(err)
	}

	w.Header().Set("Content-Type", "application/json")
	err = json.NewEncoder(w).Encode(body)
	if err != nil {
		panic(err)
	}
}

type Body struct {
	Colors []Color `json:"colors"`
}

type Color struct {
	Color    string `json:"color,omitempty"`
	Category string `json:"category,omitempty"`
	Type     string `json:"type,omitempty"`
	Code     Code   `json:"code,omitempty"`
}

type Code struct {
	RGBA []int  `json:"rgba,omitempty"`
	Hex  string `json:"hex,omitempty"`
}