Go to file
Dennis Oehme 048d9952a4 Bugfix: Printing is not working via socket adapter 2021-05-06 02:24:53 +02:00
.gitignore
CREDITS.MD Added adapter implementation including Socket Adapter 2021-02-26 09:40:29 +01:00
LICENSE
README.md prepare v1.6.0 release 2021-04-08 17:53:06 +02:00
adapter-http.go Added adapter implementation including Socket Adapter 2021-02-26 09:40:29 +01:00
adapter-socket.go Bugfix: Printing is not working via socket adapter 2021-05-06 02:24:53 +02:00
adapter.go Added adapter implementation including Socket Adapter 2021-02-26 09:40:29 +01:00
attribute.go fix typo 2020-08-07 15:22:02 +02:00
attribute_test.go fixed type for ipp tags 2020-03-09 12:47:23 +01:00
constants.go fix typo 2021-05-04 16:35:43 -05:00
cups-client.go Address comments from review 2021-02-26 11:24:22 +01:00
error.go added more code comments for docs 2020-03-28 00:27:56 +01:00
go.mod - changed the get jobs method to fetch jobs from printer, classes or both 2019-12-26 16:46:08 +01:00
ipp-client.go Fix GetJobAttributes method 2021-04-02 21:38:19 +03:00
request.go Rename reqest.go to request.go 2020-08-05 10:29:29 +02:00
response.go removed status code check in response decoder 2020-03-30 12:25:03 +02:00
utils.go fixed some c&p comment errors 2020-03-28 00:30:48 +01:00

README.md

go-ipp

Version Documentation Go Report Card Licence

Go Get

To get the package, execute:

go get -u github.com/phin1x/go-ipp

Features

  • basic ipp 2.0 compatible Client
  • extended client for cups server
  • create custom ipp requests
  • parse ipp responses and ipp control files

Example

Print a file with the ipp client

package main

import "github.com/phin1x/go-ipp"

func main() {
    // create a new ipp client
    client := ipp.NewIPPClient("printserver", 631, "user", "password", true)
    // print file
    client.PrintFile("/path/to/file", "my-printer", map[string]interface{}{})
}

Craft and send a custom request


package main

import "github.com/phin1x/go-ipp"

func main() {             
    // define a ipp request
    req := ipp.NewRequest(OperationGetJobs, 1)
    req.OperationAttributes[ipp.AttributeWhichJobs] = "completed"
    req.OperationAttributes[ipp.AttributeMyJobs] = myJobs
    req.OperationAttributes[ipp.AttributeFirstJobID] = 42
    req.OperationAttributes[ipp.AttributeRequestingUserName] = "fabian"
    
    // encode request to bytes
    payload, err := req.Encode()
    if err != nil {
        panic(err)
    }
    
    // send ipp request to remote server via http
    httpReq, err := http.NewRequest("POST", "http://my-print-server:631/printers/my-printer", bytes.NewBuffer(payload))
    if err != nil {
        panic(err)
    }
    
    // set ipp headers
    httpReq.Header.Set("Content-Length", len(payload))
    httpReq.Header.Set("Content-Type", ipp.ContentTypeIPP)
    
    httpClient := &http.Client()
    httpResp, err := httpClient.Do(httpReq)
    if err != nil {
        panic(err)
    }
    defer httpResp.Body.Close()
    
    // response must be 200 for a successful operation
    // other possible http codes are: 
    // - 500 -> server error
    // - 426 -> sever requests a encrypted connection
    // - 401 -> forbidden -> need authorization header or user is not permitted
    if httpResp.StatusCode != 200 {
        panic("non 200 response from server")
    }
    
    // decode ipp response
    resp, err := ipp.NewResponseDecoder(httpResp.Body).Decode(nil)
    if err != nil {
        panic(err)
    }
    
    // check if the response status is "ok"
    if resp.StatusCode == ipp.StatusOk {
        panic(resp.StatusCode)
    }
    
    // do something with the returned data
    for _, job := resp.JobAttributes {
        // ...
    }
}

Licence

Apache Licence Version 2.0