cleanup
This commit is contained in:
parent
789097fd79
commit
54604ff488
|
@ -1,13 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
// "os"
|
||||
"os/exec"
|
||||
"time"
|
||||
"math/rand"
|
||||
|
@ -27,6 +25,7 @@ const(
|
|||
type Agent struct {
|
||||
AgentName string `json:"agentName"`
|
||||
AgentID string `json:"agentId"`
|
||||
AgentType string `json:"agentType"`
|
||||
AgentIP string `json:"agentIp"`
|
||||
InitialContact string `json:"initialContact"`
|
||||
LastContact string `json:"lastContact"`
|
||||
|
@ -40,18 +39,6 @@ type Message struct {
|
|||
var conn *websocket.Conn
|
||||
|
||||
func registerAgent(agentName, agentId, agentIp, agentType string) error {
|
||||
// agent:= Agent{
|
||||
// AgentName: agentName,
|
||||
// InitialContact: time.Now().Format(time.RFC3339),
|
||||
// LastContact: time.Now().Format(time.RFC3339),
|
||||
// }
|
||||
|
||||
// jsonData, err := json.Marshal(agent)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Error marshaling agent data: %v", err)
|
||||
// }
|
||||
|
||||
// resp, err := http.Post(registerURL, "application/json", bytes.NewBuffer(jsonData))
|
||||
|
||||
form := url.Values{}
|
||||
form.Add("agentId", agentId)
|
||||
|
@ -170,7 +157,6 @@ func randomInt(length int) int {
|
|||
|
||||
func main() {
|
||||
agentName := "Agent-001"
|
||||
// agentId := "1234"
|
||||
agentId := strconv.Itoa(randomInt(5))
|
||||
agentIp := "127.0.0.1"
|
||||
agentType := "BaseAgent"
|
||||
|
|
24
main.go
24
main.go
|
@ -2,17 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
// "encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// "errors"
|
||||
"fmt"
|
||||
// "io"
|
||||
// "io/ioutil"
|
||||
|
||||
// "net"
|
||||
"database/sql"
|
||||
"html/template"
|
||||
"log"
|
||||
|
@ -55,15 +49,6 @@ func processError(err error) {
|
|||
os.Exit(2)
|
||||
}
|
||||
|
||||
type Agent struct {
|
||||
AgentID int `json:"agentId"`
|
||||
AgentName string `json:"agentName"`
|
||||
InitialContact string `json:"initialContact"`
|
||||
LastContact string `json:"lastContact"`
|
||||
IPv4Address string `json:"IPv4Address"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
tmpl, _ = template.ParseGlob("templates/*.html")
|
||||
}
|
||||
|
@ -105,24 +90,19 @@ func agentsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
switch r.Method {
|
||||
case http.MethodDelete:
|
||||
// deleteAgent(w, r, agentId)
|
||||
api.DeleteAgent(db, w, r, agentId)
|
||||
listAgents(w,r)
|
||||
// renderTemplate(w, "templates/partials/agent_list.html", agents)
|
||||
case http.MethodGet:
|
||||
if agentId == "" {
|
||||
listAgents(w, r)
|
||||
} else {
|
||||
// getAgent(w, r, agentId)
|
||||
agent, _ := api.GetAgent(db, w, r, agentId)
|
||||
renderTemplate(w, "templates/partials/agent_detail.html", agent)
|
||||
}
|
||||
case http.MethodPost:
|
||||
// createAgent(w, r)
|
||||
api.CreateAgent(db, w, r)
|
||||
listAgents(w, r)
|
||||
case http.MethodPut:
|
||||
// updateAgent(w, r, agentId)
|
||||
api.UpdateAgent(db, w, r, agentId)
|
||||
listAgents(w, r)
|
||||
default:
|
||||
|
@ -162,12 +142,8 @@ func main() {
|
|||
|
||||
websocketServer := websocketserver.Server()
|
||||
|
||||
|
||||
webMux := http.NewServeMux()
|
||||
webMux.HandleFunc("/", getHomepage)
|
||||
// webMux.HandleFunc("/index", getRoot)
|
||||
// webMux.HandleFunc("/hello", getHello)
|
||||
// webMux.HandleFunc("/agents", fetchAgents)
|
||||
webMux.HandleFunc("/agents", agentsHandler)
|
||||
webMux.HandleFunc("/agentNames", getAgentNames)
|
||||
webMux.HandleFunc("/agents/{agentId}", agentsHandler)
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
|
Loading…
Reference in New Issue