github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/daemon/logger/proxy.go (about)

     1  package logger // import "github.com/Prakhar-Agarwal-byte/moby/daemon/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 ret logPluginProxyCapabilitiesResponse
    78  
    79  	if err = pp.Call("LogDriver.Capabilities", nil, &ret); err != nil {
    80  		return
    81  	}
    82  
    83  	cap = ret.Cap
    84  
    85  	if ret.Err != "" {
    86  		err = errors.New(ret.Err)
    87  	}
    88  
    89  	return
    90  }
    91  
    92  type logPluginProxyReadLogsRequest struct {
    93  	Info   Info
    94  	Config ReadConfig
    95  }
    96  
    97  func (pp *logPluginProxy) ReadLogs(info Info, config ReadConfig) (stream io.ReadCloser, err error) {
    98  	var req logPluginProxyReadLogsRequest
    99  
   100  	req.Info = info
   101  	req.Config = config
   102  	return pp.Stream("LogDriver.ReadLogs", req)
   103  }