github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/daemon/logger/proxy.go (about)

     1  package logger
     2  
     3  import (
     4  	"errors"
     5  	"io"
     6  )
     7  
     8  type client interface {
     9  	Call(string, interface{}, interface{}) error
    10  	Stream(string, interface{}) (io.ReadCloser, error)
    11  }
    12  
    13  type logPluginProxy struct {
    14  	client
    15  }
    16  
    17  type logPluginProxyStartLoggingRequest struct {
    18  	File string
    19  	Info Info
    20  }
    21  
    22  type logPluginProxyStartLoggingResponse struct {
    23  	Err string
    24  }
    25  
    26  func (pp *logPluginProxy) StartLogging(file string, info Info) (err error) {
    27  	var (
    28  		req logPluginProxyStartLoggingRequest
    29  		ret logPluginProxyStartLoggingResponse
    30  	)
    31  
    32  	req.File = file
    33  	req.Info = info
    34  	if err = pp.Call("LogDriver.StartLogging", req, &ret); err != nil {
    35  		return
    36  	}
    37  
    38  	if ret.Err != "" {
    39  		err = errors.New(ret.Err)
    40  	}
    41  
    42  	return
    43  }
    44  
    45  type logPluginProxyStopLoggingRequest struct {
    46  	File string
    47  }
    48  
    49  type logPluginProxyStopLoggingResponse struct {
    50  	Err string
    51  }
    52  
    53  func (pp *logPluginProxy) StopLogging(file string) (err error) {
    54  	var (
    55  		req logPluginProxyStopLoggingRequest
    56  		ret logPluginProxyStopLoggingResponse
    57  	)
    58  
    59  	req.File = file
    60  	if err = pp.Call("LogDriver.StopLogging", req, &ret); err != nil {
    61  		return
    62  	}
    63  
    64  	if ret.Err != "" {
    65  		err = errors.New(ret.Err)
    66  	}
    67  
    68  	return
    69  }
    70  
    71  type logPluginProxyCapabilitiesResponse struct {
    72  	Cap Capability
    73  	Err string
    74  }
    75  
    76  func (pp *logPluginProxy) Capabilities() (cap Capability, err error) {
    77  	var (
    78  		ret logPluginProxyCapabilitiesResponse
    79  	)
    80  
    81  	if err = pp.Call("LogDriver.Capabilities", nil, &ret); err != nil {
    82  		return
    83  	}
    84  
    85  	cap = ret.Cap
    86  
    87  	if ret.Err != "" {
    88  		err = errors.New(ret.Err)
    89  	}
    90  
    91  	return
    92  }
    93  
    94  type logPluginProxyReadLogsRequest struct {
    95  	Info   Info
    96  	Config ReadConfig
    97  }
    98  
    99  func (pp *logPluginProxy) ReadLogs(info Info, config ReadConfig) (stream io.ReadCloser, err error) {
   100  	var (
   101  		req logPluginProxyReadLogsRequest
   102  	)
   103  
   104  	req.Info = info
   105  	req.Config = config
   106  	return pp.Stream("LogDriver.ReadLogs", req)
   107  }