package
This commit is contained in:
parent
6003765d39
commit
0e5b3a9dc2
1
.gitignore
vendored
1
.gitignore
vendored
@ -43,3 +43,4 @@ datediff/datediff
|
||||
example-json/example-json
|
||||
financialjson/financialjson
|
||||
statecsv2json/statecsv2json
|
||||
converter-main/converter-main
|
||||
|
16
converter-main/main.go
Normal file
16
converter-main/main.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "os"
|
||||
import "meutel.net/meutel/go-examples/converter"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 3 {
|
||||
log.Fatalln("Needs 2 arguments")
|
||||
}
|
||||
input := os.Args[1]
|
||||
convTo := os.Args[2]
|
||||
|
||||
fmt.Println(converter.Convert(input, convTo))
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package main
|
||||
package converter
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "os"
|
||||
import "strconv"
|
||||
import "strings"
|
||||
|
||||
@ -23,13 +22,7 @@ var (
|
||||
convVal float64
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 3 {
|
||||
log.Fatalln("Needs 2 arguments")
|
||||
}
|
||||
input := os.Args[1]
|
||||
convTo := os.Args[2]
|
||||
|
||||
func Convert(input, convTo string) string {
|
||||
switch {
|
||||
case strings.HasSuffix(input, markerKm):
|
||||
inUnit = markerKm
|
||||
@ -58,8 +51,6 @@ func main() {
|
||||
asMeter = inVal
|
||||
}
|
||||
|
||||
// fmt.Println(inVal, inUnit, asMeter, convTo)
|
||||
|
||||
switch convTo {
|
||||
case markerMiles:
|
||||
convVal = asMeter / (MilesToKm * 1000)
|
||||
@ -72,5 +63,6 @@ func main() {
|
||||
default:
|
||||
log.Fatalln("Invalid unit: " + convTo)
|
||||
}
|
||||
fmt.Printf("%.2f%s\n", convVal, convTo)
|
||||
|
||||
return fmt.Sprintf("%.2f%s", convVal, convTo)
|
||||
}
|
Loading…
Reference in New Issue
Block a user