// Package stdio provide some standard IO util functions.
package stdio import ( ) // DiscardReader anything from the reader func ( io.Reader) { _, _ = io.Copy(io.Discard, ) } // ReadString read contents from io.Reader, return empty string on error func ( io.Reader) string { , := io.ReadAll() if != nil { return "" } return string() } // MustReadReader read contents from io.Reader, will panic on error func ( io.Reader) []byte { , := io.ReadAll() if != nil { panic() } return } // NewIOReader instance by input: string, bytes, io.Reader func ( any) io.Reader { switch typIn := .(type) { case []byte: return bytes.NewReader() case string: return strings.NewReader() case io.Reader: return } panic("invalid input type for create reader") } // NewScanner instance by input data or reader func ( any) *bufio.Scanner { switch typIn := .(type) { case io.Reader: return bufio.NewScanner() case []byte: return bufio.NewScanner(bytes.NewReader()) case string: return bufio.NewScanner(strings.NewReader()) case *bufio.Scanner: return default: panic("invalid input type for create scanner") } } // SafeClose close io.Closer, ignore error func ( io.Closer) { _ = .Close() } // WriteByte to stdout, will ignore error func ( byte) { _, _ = os.Stdout.Write([]byte{}) } // WriteBytes to stdout, will ignore error func ( []byte) { _, _ = os.Stdout.Write() } // WritelnBytes to stdout, will ignore error func ( []byte) { _, _ = os.Stdout.Write() _, _ = os.Stdout.Write([]byte("\n")) } // WriteString to stdout. will ignore error func ( string) { _, _ = os.Stdout.WriteString() } // Writeln string to stdout. will ignore error func ( string) { _, _ = os.Stdout.WriteString() _, _ = os.Stdout.Write([]byte("\n")) }