40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
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)
|
|
|
|
}
|