From 54c881b3bea1833bba9e12d77415a399c1575fb1 Mon Sep 17 00:00:00 2001
From: ren yuze
Date: Wed, 5 Apr 2023 23:33:03 +0800
Subject: [PATCH] update
---
calc/calc.go | 49 ++++++++++++++
ftp/ftp.go | 1 -
httpserver/mime.go | 2 +-
httpserver/server.go | 148 ++++++++++++++++++++++++++++++++++---------
main.go | 12 +++-
ping/ping.go | 1 +
6 files changed, 179 insertions(+), 34 deletions(-)
create mode 100644 calc/calc.go
create mode 100644 ping/ping.go
diff --git a/calc/calc.go b/calc/calc.go
new file mode 100644
index 0000000..02cf571
--- /dev/null
+++ b/calc/calc.go
@@ -0,0 +1,49 @@
+package calc
+
+import (
+ "b612.me/starlog"
+ "b612.me/staros"
+ "errors"
+ "fmt"
+ "github.com/spf13/cobra"
+ "strconv"
+ "strings"
+)
+
+var Cmd = &cobra.Command{
+ Use: "calc",
+ Short: "计算器",
+ Long: "简单的计算器",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if len(args) == 0 {
+ starlog.Errorln("请至少输入一个算式")
+ return errors.New("no sentense")
+ }
+ var res []string
+ printRes := func() {
+ for k, v := range res {
+ fmt.Println(args[k], "=", v)
+ }
+ }
+ for k, v := range args {
+ for i := k; i > 0; i-- {
+ v = strings.ReplaceAll(v, "$"+strconv.Itoa(i), res[i-1])
+ }
+ v = strings.ReplaceAll(v, "x", "*")
+ v = strings.ReplaceAll(v, "X", "*")
+ v = strings.ReplaceAll(v, "×", "*")
+ v = strings.ReplaceAll(v, "÷", "*")
+ v = strings.ReplaceAll(v, "(", "(")
+ v = strings.ReplaceAll(v, ")", ")")
+ c, err := staros.Calc(v)
+ if err != nil {
+ printRes()
+ starlog.Errorf("calc %s Error:%v\n", v, err)
+ return err
+ }
+ res = append(res, strconv.FormatFloat(c, 'f', -1, 64))
+ }
+ printRes()
+ return nil
+ },
+}
diff --git a/ftp/ftp.go b/ftp/ftp.go
index 8591fe0..fcd78a5 100644
--- a/ftp/ftp.go
+++ b/ftp/ftp.go
@@ -30,7 +30,6 @@ var Cmd = &cobra.Command{
Hostname: ip,
Auth: &server.SimpleAuth{Name: username, Password: pwd},
}
-
log.Printf("Starting ftp server on %v:%v", opts.Hostname, opts.Port)
log.Printf("Username %v, Password %v", username, pwd)
server := server.NewServer(opts)
diff --git a/httpserver/mime.go b/httpserver/mime.go
index 4a7d6c0..41ee371 100644
--- a/httpserver/mime.go
+++ b/httpserver/mime.go
@@ -5,7 +5,7 @@ import "path/filepath"
func (h *HttpServer) FileType(name string) string {
ext := filepath.Ext(name)
if len(ext) == 0 || ext == "." {
- return "文件"
+ return "其他文件"
}
ext = ext[1:]
mimeMap := map[string]string{
diff --git a/httpserver/server.go b/httpserver/server.go
index afcbc31..cd3ca9c 100644
--- a/httpserver/server.go
+++ b/httpserver/server.go
@@ -82,11 +82,31 @@ var htmlTitle string = `
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
+ position: relative;
}
- th:hover {
- cursor: pointer;
- background-color: #ddd;
+ th[data-sort]:before {
+ content: "▼";
+ display: inline-block;
+ height: 20px;
+ width: 20px;
+ margin-right: 10px;
+ vertical-align: middle;
+ position: absolute;
+ right: 0;
+ top: 50%%;
+ transform: translateY(-50%%);
+ opacity: 0.3;
+ transition: all 0.2s ease-in-out;
+ }
+
+ th[data-sort].asc:before {
+ content: "▲";
+ opacity: 1;
+ }
+
+ th:hover:before {
+ opacity: 1;
}
.filename {
@@ -112,49 +132,69 @@ var htmlTitle string = `
+
-
`
var htmlTail = `
Name
- Modified
- Size
- Type
+ Name
+ Modified
+ Size
+ Type
+
+
-
B612.Me © Apache 2.0 License
+