From e0a0c88d95a6f1e69d99eb0d901c21d595b45d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=C3=B6lver?= Date: Mon, 28 Dec 2020 20:16:59 +0100 Subject: [PATCH] Start client implementation. --- client/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 client/main.go diff --git a/client/main.go b/client/main.go new file mode 100644 index 0000000..2b2299d --- /dev/null +++ b/client/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "bytes" + "fmt" + "ippserver/packages/ipp" + "net/http" + + log "github.com/sirupsen/logrus" +) + +//application/ipp +// brn30055cb5e3ae.local:631/ipp/print +func main() { + + customFormatter := new(log.TextFormatter) + customFormatter.TimestampFormat = "2006-01-02 15:04:05" + log.SetFormatter(customFormatter) + customFormatter.FullTimestamp = true + log.SetLevel(log.DebugLevel) + + const printerUri = "brn30055cb5e3ae.local:631/ipp/print" + + request := ipp.NewRequest(ipp.GetPrinterAttributes, 10) + request.AddOperatonAttribute(ipp.NewCharSetValue("attributes-charset", "utf-8")) + request.AddOperatonAttribute(ipp.NewNaturalLanguage("attributes-natural-language", "en")) + request.AddOperatonAttribute(ipp.NewUriValue("printer-uri", "ipp://"+printerUri)) + r := request.Marshal() + b := bytes.NewBuffer(r) + httpResponse, err := http.Post("http://"+"brn30055cb5e3ae.local:631/ipp/print", "application/ipp", b) + if err != nil { + fmt.Print(err) + return + } + rb := ipp.NewResponse(0, 0) + rb.UnMarshal(httpResponse.Body) + fmt.Print(r) + +}