github.com/packtpublishing/learning-functional-programming-in-go@v0.0.0-20230130084745-8b849f6d58c4/Chapter05/misc/misc.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  	"time"
     7  )
     8  
     9  type Hash interface {
    10  	io.Writer
    11  	Sum(b []byte) []byte
    12  	Reset()
    13  	Size() int
    14  	BlockSize() int
    15  }
    16  
    17  //func ReadAll(r io.Reader) ([]byte, error)
    18  //
    19  //func LoggingReader(r io.Reader) io.Reader
    20  //func LimitingReader(r io.Reader, n int64) io.Reader
    21  //func ErrorInjector(r io.Reader) io.Reader
    22  
    23  // The File interface is implemented by os.File.  App specific
    24  // implementations may add concurrency, caching, stats, fuzzing, etc.
    25  type File interface {
    26  	io.ReaderAt
    27  	io.WriterAt
    28  	io.Closer
    29  	Stat() (os.FileInfo, error)
    30  	Sync() error
    31  	Truncate(size int64) error
    32  }
    33  
    34  type File interface {
    35  	io.Reader
    36  	io.ReaderAt
    37  	io.Seeker
    38  	io.Closer
    39  }
    40  
    41  type File interface {
    42  	io.ReadSeeker
    43  	io.Closer
    44  	Name() string
    45  }
    46  // File is an interface to access the file part of a multipart message.
    47  // Its contents may be either stored in memory or on disk.
    48  // If stored on disk, the File's underlying concrete type will be an *os.File.
    49  type File interface {
    50  	io.Reader
    51  	io.ReaderAt
    52  	io.Seeker
    53  	io.Closer
    54  }
    55  
    56  
    57  type Reader interface {
    58  	Read(p []byte) (n int, err error)
    59  }
    60  
    61  type Writer interface {
    62  	Write(p []byte) (n int, err error)
    63  }
    64  
    65  /*
    66  Pick a Product Type:
    67  (1) Appliance
    68  (2) Book
    69  (3) Clothing
    70  3
    71  Pick a Clothing Type:
    72  (1) Men
    73  (2) Women
    74  (3) Children
    75  2
    76  
    77  
    78  
    79  $ go run main.go --help
    80  
    81  Usage of main:
    82  
    83   -proxyPort int
    84  
    85      Server Port (default 8080)
    86  
    87   -serverPort int
    88  
    89      Server Port (default 3000)
    90  
    91  
    92  
    93  INFO  : 13:46:19 Metrics server listening on 127.0.0.1:3000
    94  INFO  : 13:46:20 Proxy listening on 127.0.0.1:8080
    95  DEBUG : 2017/05/17 13:46:30 requester.go:114: makeRequest:
    96  client: 13:46:30 GET http://127.0.0.1:3000
    97  DEBUG : 2017/05/17 13:46:30 metrics.go:66: - randInt: 3081
    98  DEBUG : 2017/05/17 13:46:31 decorator.go:107: backing off...
    99  client: 13:46:31 GET http://web02:3000
   100  DEBUG : 2017/05/17 13:46:31 metrics.go:66: - randInt: 2887
   101  DEBUG : 2017/05/17 13:46:32 decorator.go:107: backing off...
   102  client: 13:46:33 GET http://web03:3000
   103  DEBUG : 2017/05/17 13:46:33 metrics.go:66: - randInt: 1847
   104  DEBUG : 2017/05/17 13:46:34 decorator.go:107: backing off...
   105  INFO  : 13:46:36 FAILURE!
   106  
   107  
   108  DEBUG : 2017/05/17 13:47:30 requester.go:114: makeRequest:
   109  client: 13:47:30 GET http://web03:3000
   110  DEBUG : 2017/05/17 13:47:30 metrics.go:66: - randInt: 1445
   111  DEBUG : 2017/05/17 13:47:31 decorator.go:107: backing off...
   112  client: 13:47:31 GET http://web01:3000
   113  DEBUG : 2017/05/17 13:47:31 metrics.go:66: - randInt: 3237
   114  DEBUG : 2017/05/17 13:47:32 decorator.go:107: backing off...
   115  client: 13:47:33 GET http://web02:3000
   116  DEBUG : 2017/05/17 13:47:33 metrics.go:66: - randInt: 4106
   117  DEBUG : 2017/05/17 13:47:34 decorator.go:107: backing off...
   118  INFO  : 13:47:36 FAILURE!
   119  DEBUG : 2017/05/17 13:47:36 requester.go:65: > 7 requests done.
   120  DEBUG : 2017/05/17 13:47:40 requester.go:114: makeRequest:
   121  client: 13:47:40 GET http://web03:3000
   122  DEBUG : 2017/05/17 13:47:40 metrics.go:66: - randInt: 495
   123  INFO  : 13:47:41 SUCCESS!
   124  DEBUG : 2017/05/17 13:47:41 requester.go:65: > 8 requests done.
   125  
   126  
   127  */
   128  
   129  func main() {
   130  
   131  }