pull/8/head
zimujun20 2 years ago
parent c1222cfe2f
commit 7b70cc660e

@ -0,0 +1,47 @@
package android
import (
"fmt"
"net/http"
"database/sql"
_ "go-sqlite3-master"
"application/pkg/app"
"github.com/gin-gonic/gin"
)
func getMacAddress() (macAddress []string) {
netInterfaces, err := net.Interfaces()
if err != nil {
fmt.Printf("fail to get net interfaces: %v", err)
return macAddress
}
for _, netInterface := range netInterfaces {
MacAddress := netInterface.HardwareAddr.String()
if len(MacAddress) == 0 {
continue
}
macAddress = append(macAddress, MacAddress)
}
return macAddress
}
func sendMacAddress(c *gin.Context) {
appG := app.Gin{C: c}
macAddress = getMacAddress()
db, err := sql.Open("sqlite3", "info.db")
if err != nil {
fmt.Println(err)
}
defer db.Close()
db.Exec(`insert into Endpoint values (?,?)`, macAddress, 0)
appG.Response(http.StatusOK, "成功", null)
}
func mediaPipe(c *gin.Context) {
appG := app.Gin{C: c}
//这里将视频流转化为自然语言
data :=
appG.Response(http.StatusOK, "成功", data)
}

@ -0,0 +1,41 @@
package android
import (
"fmt"
"database/sql"
_ "go-sqlite3-master"
"application/pkg/app"
"github.com/gin-gonic/gin"
)
func updateAverage (c *gin.Context) {
appG := app.Gin{C: c}
macAddress = getMacAddress()
db, err := sql.Open("sqlite3", "info.db")
if err != nil {
fmt.Println(err)
}
defer db.Close()
db.Exec(`update Endpoint set times = times + 1 where macAddress = ?`, macAddress)
rows, err := db.Query(`select SUM( times ) from Endpoint`)
defer rows.Close()
var sumOfTimes int
rows.Next()
rows.Scan(&sumOfTimes)
rows, err := db.Query(`select COUNT( macAddress ) from Endpoint`)
defer rows.Close()
var countOfMacAddress int
rows.Next()
rows.Scan(&countOfMacAddress)
db.Exec(`update Average set average = ?/?`sendMacAddress, countOfMacAddress)
appG.Response(http.StatusOK, "成功", null)
}
func wordSend (c *gin.Context) {
appG := app.Gin{C: c}
//这里获取转化好的数据
data := mediaPipe().data
updateAverage()
appG.Response(http.StatusOK, "成功", data)
}

@ -0,0 +1,54 @@
package pc
import (
"database/sql"
_ "go-sqlite3-master"
"net/http"
)
//拉取在线的算力设备
func endpoint(w http.ResponseWriter, r *http.Request) {
db, err := sql.Open("sqlite3", "info.db")
if err != nil {
fmt.Println(err)
}
defer db.Close()
rows, _ := db.Query(`select endpoint.macAddress from Endpoint where endpoint.times < Average.average;`)
defer rows.Close()
var endpoint Endpoint
var endpoints = []string {}
for rows.Next() {
rows.Scan(&endpoint.macAddress)
endpoints.append(endpoint.macAddress)
}
rows.Close()
}
func shuffle(n int) []int {
b := rand.Perm(n)
return b
}
func request(params map[string]interface{}) error {
var indexes = []int {0,1,2,3,4,5,6}
var err error
shuffle(indexes)
maxRetryTimes := 3
idx := 0
for i :=0; i < maxRetryTimes; i++ {
err = apiRequest(params, indexes[idx])
if err == nil {
break
}
idx++
}
if err != nil {
//logging
return err
}
return nil
}

@ -4,18 +4,11 @@ import (
"fmt"
"log"
"net/http"
"time"
"application/routers"
)
func main() {
timeLocal, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Printf("时区设置失败 %s", err)
}
time.Local = timeLocal
endPoint := fmt.Sprintf("0.0.0.0:%d", 8000)
server := &http.Server{
Addr: endPoint,

@ -1,4 +1,4 @@
package app
package pkg
import (
"github.com/gin-gonic/gin"

@ -0,0 +1,10 @@
package pkg
type Endpoint struct {
macAddress string //设备地址
times int //贡献算力次数
}
type Average struct {
average int //平均使用次数
}
Loading…
Cancel
Save