mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-11 17:31:44 +00:00
good good study, day day up!
This commit is contained in:
19
vendor/gopl.io/ch10/cross/main.go
generated
vendored
Normal file
19
vendor/gopl.io/ch10/cross/main.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
// See page 295.
|
||||
|
||||
// The cross command prints the values of GOOS and GOARCH for this target.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
//!+
|
||||
func main() {
|
||||
fmt.Println(runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
//!-
|
52
vendor/gopl.io/ch10/jpeg/main.go
generated
vendored
Normal file
52
vendor/gopl.io/ch10/jpeg/main.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
// See page 287.
|
||||
|
||||
//!+main
|
||||
|
||||
// The jpeg command reads a PNG image from the standard input
|
||||
// and writes it as a JPEG image to the standard output.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
_ "image/png" // register PNG decoder
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := toJPEG(os.Stdin, os.Stdout); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "jpeg: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func toJPEG(in io.Reader, out io.Writer) error {
|
||||
img, kind, err := image.Decode(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "Input format =", kind)
|
||||
return jpeg.Encode(out, img, &jpeg.Options{Quality: 95})
|
||||
}
|
||||
|
||||
//!-main
|
||||
|
||||
/*
|
||||
//!+with
|
||||
$ go build gopl.io/ch3/mandelbrot
|
||||
$ go build gopl.io/ch10/jpeg
|
||||
$ ./mandelbrot | ./jpeg >mandelbrot.jpg
|
||||
Input format = png
|
||||
//!-with
|
||||
|
||||
//!+without
|
||||
$ go build gopl.io/ch10/jpeg
|
||||
$ ./mandelbrot | ./jpeg >mandelbrot.jpg
|
||||
jpeg: image: unknown format
|
||||
//!-without
|
||||
*/
|
Reference in New Issue
Block a user