| 
									
										
										
										
											2019-05-16 23:21:20 +03:00
										 |  |  | // Copyright © 2018 Inanc Gumus | 
					
						
							|  |  |  | // Learn Go Programming Course | 
					
						
							|  |  |  | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | 
					
						
							|  |  |  | // | 
					
						
							| 
									
										
										
										
											2019-10-30 19:34:44 +03:00
										 |  |  | // For more tutorials  : https://learngoprogramming.com | 
					
						
							|  |  |  | // In-person training  : https://www.linkedin.com/in/inancgumus/ | 
					
						
							|  |  |  | // Follow me on twitter: https://twitter.com/inancgumus | 
					
						
							| 
									
										
										
										
											2019-05-16 23:21:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 01:33:55 +03:00
										 |  |  | 	"github.com/inancgumus/learngo/magic" | 
					
						
							| 
									
										
										
										
											2019-07-21 05:14:07 +03:00
										 |  |  | 	// | 
					
						
							|  |  |  | 	// Use the following one for the panicking library: | 
					
						
							| 
									
										
										
										
											2019-08-06 01:33:55 +03:00
										 |  |  | 	// magic "github.com/inancgumus/learngo/magicpanic" | 
					
						
							| 
									
										
										
										
											2019-07-21 05:14:07 +03:00
										 |  |  | 	// | 
					
						
							| 
									
										
										
										
											2019-05-16 23:21:20 +03:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	files := []string{ | 
					
						
							|  |  |  | 		"pngs/cups-jpg.png", | 
					
						
							|  |  |  | 		"pngs/forest-jpg.png", | 
					
						
							|  |  |  | 		"pngs/golden.png", | 
					
						
							|  |  |  | 		"pngs/work.png", | 
					
						
							|  |  |  | 		"pngs/shakespeare-text.png", | 
					
						
							|  |  |  | 		"pngs/empty.png", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	args := os.Args[1:] | 
					
						
							|  |  |  | 	if len(args) != 1 { | 
					
						
							|  |  |  | 		fmt.Println("png or jpg?") | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list(args[0], files) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// fmt.Println("catch me if you can!") | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func list(format string, files []string) { | 
					
						
							|  |  |  | 	valids, err := magic.Detect(format, files) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		fmt.Println(err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fmt.Printf("Correct Files:\n") | 
					
						
							|  |  |  | 	for _, valid := range valids { | 
					
						
							|  |  |  | 		fmt.Printf(" + %s\n", valid) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |