add files
This commit is contained in:
85
server/test/container.go
Normal file
85
server/test/container.go
Normal file
@@ -0,0 +1,85 @@
|
||||
/*package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/client"
|
||||
// "reflect" (use to check variable type: command [fmt.Println(reflect.TypeOf(<variable>))])
|
||||
)
|
||||
|
||||
|
||||
/* creates continer
|
||||
TODO: Function inputs , outputs to be modified
|
||||
|
||||
func create_container() (error, string){
|
||||
ctx := context.Background()
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
if err != nil {
|
||||
return err, ""
|
||||
}
|
||||
|
||||
imageName := "ubuntu:20.10"
|
||||
|
||||
out, err := cli.ImagePull(ctx, imageName, types.ImagePullOptions{})
|
||||
if err != nil {
|
||||
return err, ""
|
||||
}
|
||||
io.Copy(os.Stdout, out)
|
||||
|
||||
resp, err := cli.ContainerCreate(ctx, &container.Config{
|
||||
Image: imageName,
|
||||
}, nil, nil, nil, "")
|
||||
|
||||
if err != nil {
|
||||
return err, ""
|
||||
}
|
||||
|
||||
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
|
||||
return err, ""
|
||||
}
|
||||
|
||||
return nil, string(resp.ID)
|
||||
}
|
||||
|
||||
/* returns all containers running
|
||||
func containers_running()(error, []types.Container){
|
||||
ctx := context.Background()
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
if err != nil {
|
||||
return err ,nil
|
||||
}
|
||||
|
||||
containers, err := cli.ContainerList(ctx, types.ContainerListOptions{})
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
return nil ,containers
|
||||
}
|
||||
|
||||
/* function to remove container from running
|
||||
func delete_container(container_id string) (error, string){
|
||||
ctx := context.Background()
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
if err != nil {
|
||||
return err ,""
|
||||
}
|
||||
if err := cli.ContainerStop(ctx, container_id, nil); err != nil {
|
||||
return err ,""
|
||||
}
|
||||
return nil ,"Success"
|
||||
}
|
||||
|
||||
func main(){
|
||||
_, containers := containers_running()
|
||||
fmt.Println(containers)
|
||||
_, container_id := create_container()
|
||||
fmt.Println(container_id)
|
||||
//_, status := delete_container(container_id)
|
||||
//fmt.Println(status)
|
||||
} */
|
||||
28
server/test/mDNS.go
Normal file
28
server/test/mDNS.go
Normal file
@@ -0,0 +1,28 @@
|
||||
/*package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/pion/mdns"
|
||||
"golang.org/x/net/ipv4"
|
||||
)
|
||||
|
||||
func main() {
|
||||
server, err := zeroconf.Register("GoZeroconf", "_workstation._tcp", "local.", 42424, []string{"txtv=0", "lo=1", "la=2"}, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer server.Shutdown()
|
||||
|
||||
// Clean exit.
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
select {
|
||||
case <-sig:
|
||||
// Exit by user
|
||||
case <-time.After(time.Second * 120):
|
||||
// Exit by timeout
|
||||
}
|
||||
|
||||
log.Println("Shutting down.")
|
||||
}*/
|
||||
22
server/test/portforwarding.go
Normal file
22
server/test/portforwarding.go
Normal file
@@ -0,0 +1,22 @@
|
||||
/*package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jackpal/gateway"
|
||||
natpmp "github.com/jackpal/go-nat-pmp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gatewayIP, err := gateway.DiscoverGateway()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
client := natpmp.NewClient(gatewayIP)
|
||||
response, err := client.GetExternalAddress()
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("External IP address: %v\n", response.ExternalIPAddress)
|
||||
}*/
|
||||
Reference in New Issue
Block a user