Mercurial > mercurial > hgweb_golang.cgi
comparison src/entai_app/entai_app.go @ 5:e4066309b04f
refactoring.
author | pyon@macmini |
---|---|
date | Sun, 23 Oct 2016 14:00:39 +0900 |
parents | ca866a38a6a0 |
children | f4ba4cfb09fd |
comparison
equal
deleted
inserted
replaced
4:4c6bfc90d75c | 5:e4066309b04f |
---|---|
1 /****************************************************************************/ | 1 /****************************************************************************/ |
2 /* Entai_app.go */ | 2 /* Entai_app.go */ |
3 /* Last Change: 2016-10-15 Sat 19:29:24. */ | 3 /* Last Change: 2016-10-23 Sun 13:23:32. */ |
4 /* By T.Mutoh */ | 4 /* By T.Mutoh */ |
5 /****************************************************************************/ | 5 /****************************************************************************/ |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
11 "encoding/csv" | 11 "encoding/csv" |
12 "flag" | 12 "flag" |
13 "fmt" | 13 "fmt" |
14 "io" | 14 "io" |
15 "log" | 15 "log" |
16 "net/http" | |
16 "os" | 17 "os" |
17 "strconv" | 18 "strconv" |
18 "strings" | 19 "strings" |
19 "time" | 20 "time" |
20 | 21 |
94 fmt.Fprint( os.Stderr, e.GetRates() ) | 95 fmt.Fprint( os.Stderr, e.GetRates() ) |
95 os.Exit( 0 ) | 96 os.Exit( 0 ) |
96 | 97 |
97 // Server-mode ( not implement ) | 98 // Server-mode ( not implement ) |
98 case *s : | 99 case *s : |
99 *p = 8080 | 100 s := fmt.Sprintf( "localhost:%d", *p ) |
100 fmt.Fprint( os.Stderr, "server mode is not implemented.\n" ) | 101 http.HandleFunc( "/", httpHandler ) |
101 os.Exit( 1 ) | 102 log.Fatal( http.ListenAndServe( s, nil ) ) |
102 | 103 |
103 // Intaractive-mode | 104 // Intaractive-mode |
104 case *d : | 105 case *d : |
105 printTile() | 106 printTile() |
106 fmt.Print( e.GetRates() ) | 107 fmt.Print( e.GetRates() ) |
237 fmt.Printf( "%s > %s\n", prompt, s ) | 238 fmt.Printf( "%s > %s\n", prompt, s ) |
238 } | 239 } |
239 return s | 240 return s |
240 } | 241 } |
241 | 242 |
243 func httpHandler( w http.ResponseWriter, r *http.Request ) { | |
244 fmt.Fprintf( w, "RemoteAddr: %q\n", r.RemoteAddr ) | |
245 if err := r.ParseForm(); err != nil { | |
246 log.Print( err ) | |
247 } | |
248 for k, v := range r.Form { | |
249 fmt.Fprintf( w, "%q: %q\n", k, v ) | |
250 } | |
251 } | |
252 | |
242 func printTile() { | 253 func printTile() { |
243 fmt.Fprint( os.Stderr, "\n==================================================\n" ) | 254 fmt.Fprint( os.Stderr, "\n==================================================\n" ) |
244 fmt.Fprintf( os.Stderr, " Entai_app ver %s ( 2016.10.19 ) - since 2016\n", ver ) | 255 fmt.Fprintf( os.Stderr, " Entai_app ver %s ( 2016.10.19 ) - since 2016\n", ver ) |
245 fmt.Fprint( os.Stderr, "==================================================\n\n" ) | 256 fmt.Fprint( os.Stderr, "==================================================\n\n" ) |
246 } | 257 } |