You've already forked hex-microservice
mirror of
https://github.com/tensor-programming/hex-microservice.git
synced 2026-04-24 19:54:06 +02:00
48 lines
867 B
Go
48 lines
867 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"github.com/vmihailenco/msgpack"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/tensor-programming/hex-microservice/shortener"
|
|
)
|
|
|
|
func httpPort() string {
|
|
port := "8000"
|
|
if os.Getenv("PORT") != "" {
|
|
port = os.Getenv("PORT")
|
|
}
|
|
return fmt.Sprintf(":%s", port)
|
|
}
|
|
|
|
func main() {
|
|
address := fmt.Sprintf("http://localhost%s", httpPort())
|
|
redirect := shortener.Redirect{}
|
|
redirect.URL = "https://github.com/tensor-programming?tab=repositories"
|
|
|
|
body, err := msgpack.Marshal(&redirect)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
resp, err := http.Post(address, "application/x-msgpack", bytes.NewBuffer(body))
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err = ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
msgpack.Unmarshal(body, &redirect)
|
|
|
|
log.Printf("%v\n", redirect)
|
|
}
|