github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/utils/types.go (about) 1 /* 2 * Copyright (c) 2020-present unTill Pro, Ltd. 3 * @author Denis Gribanov 4 */ 5 6 package coreutils 7 8 import ( 9 "io/fs" 10 "net/http" 11 "os" 12 "path/filepath" 13 "time" 14 15 "github.com/voedger/voedger/pkg/istructs" 16 ) 17 18 type EmbedFS interface { 19 Open(name string) (fs.File, error) 20 ReadDir(name string) ([]fs.DirEntry, error) 21 ReadFile(name string) ([]byte, error) 22 } 23 24 type HTTPResponse struct { 25 Body string 26 HTTPResp *http.Response 27 expectedSysErrorCode int 28 expectedHTTPCodes []int 29 } 30 31 type ReqOptFunc func(opts *reqOpts) 32 33 type FuncResponse struct { 34 *HTTPResponse 35 Sections []struct { 36 Elements [][][][]interface{} `json:"elements"` 37 } `json:"sections"` 38 NewIDs map[string]int64 39 CurrentWLogOffset istructs.Offset 40 SysError SysError `json:"sys.Error"` 41 CmdResult map[string]interface{} `json:"Result"` 42 } 43 44 type FuncError struct { 45 SysError 46 ExpectedHTTPCodes []int 47 } 48 49 type IHTTPClient interface { 50 Req(urlStr string, body string, optFuncs ...ReqOptFunc) (*HTTPResponse, error) 51 CloseIdleConnections() 52 } 53 54 type retrier struct { 55 macther func(err error) bool 56 timeout time.Duration 57 delay time.Duration 58 } 59 60 type TimeFunc func() time.Time 61 62 type PathReader struct { 63 rootPath string 64 } 65 66 func NewPathReader(rootPath string) *PathReader { 67 return &PathReader{ 68 rootPath: rootPath, 69 } 70 } 71 72 func (r *PathReader) Open(name string) (fs.File, error) { 73 return os.Open(filepath.Join(r.rootPath, name)) 74 } 75 76 func (r *PathReader) ReadDir(name string) ([]os.DirEntry, error) { 77 return os.ReadDir(filepath.Join(r.rootPath, name)) 78 } 79 80 func (r *PathReader) ReadFile(name string) ([]byte, error) { 81 return os.ReadFile(filepath.Join(r.rootPath, name)) 82 } 83 84 type IErrUnwrapper interface { 85 Unwrap() []error 86 } 87 88 type CUD struct { 89 Fields map[string]interface{} `json:"fields"` 90 } 91 92 type CUDs struct { 93 Cuds []CUD `json:"cuds"` 94 } 95 96 type IReadFS interface { 97 fs.ReadDirFS 98 fs.ReadFileFS 99 } 100 101 // moved here to avoid import cycle: state -> federation (for cmd storage) -> blobber (IFederation.UploadBLOBs([]blobber.BLOB)) -> state 102 type BLOB struct { 103 FieldName string 104 Content []byte 105 Name string 106 MimeType string 107 }