first commit

This commit is contained in:
r0n1n7an 2024-04-20 16:19:54 +08:00
commit d31f48788e
4 changed files with 54 additions and 0 deletions

BIN
Calc.exe Normal file

Binary file not shown.

47
Calc.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"flag"
"fmt"
"os"
"github.com/Knetic/govaluate"
)
var exp string = ""
var ver string = ""
var vsn bool = false
func init() {
flag.BoolVar(&vsn, "v", false, "Show Program Version")
flag.StringVar(&exp, "e", "", "Evaluable Expression")
flag.Parse()
}
func main() {
if vsn {
_ShowVersion()
os.Exit(0)
}
if exp == "" {
flag.Usage()
os.Exit(1)
}
expression, err := govaluate.NewEvaluableExpression(exp)
if err != nil {
fmt.Printf("[ERR] %v\r\n", err)
os.Exit(1)
}
result, err := expression.Evaluate(nil)
if err != nil {
fmt.Printf("[ERR] %v\r\n", err)
os.Exit(1)
}
fmt.Printf("Result=%v\r\n", result)
}
func _ShowVersion() {
fmt.Printf("%s\r\nAuthor: %s\r\nVersion: %s\r\n", os.Args[0], "TE / Vayne Tan", ver)
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module Calc
go 1.20
require github.com/Knetic/govaluate v3.0.0+incompatible

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=