aboutsummaryrefslogtreecommitdiff
path: root/api/routes.go
blob: 103de040806872d941c225082075c277bb79f4d3 (plain) (blame)
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
package api

import (
	"fmt"
	"net/http"

	"github.com/jackyzha0/ctrl-v/db"

	log "github.com/sirupsen/logrus"
)

func healthCheckFunc(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "status ok")
}

func insertFunc(w http.ResponseWriter, r *http.Request) {
	// get content
	_ = r.ParseMultipartForm(0)
	content := r.FormValue("content")

	// get ip
	ip := getIP(r)

	log.Infof("got content '%s' and ip '%s'", content, ip)

	// insert content
	err := db.New(ip, content)
	if err != nil {
		fmt.Fprintf(w, "got err: %s", err.Error())
	}
}