Skip to content

Commit 08f77fd

Browse files
committed
First commit (may be broken)
0 parents  commit 08f77fd

12 files changed

+433
-0
lines changed

LICENSE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright 2019 Harry Ickeringill
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

api/api.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package api
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
func handleInfo(w http.ResponseWriter, r *http.Request) {
10+
res := prov.ListServers()
11+
json.NewEncoder(w).Encode(res)
12+
}
13+
14+
func handleStart(w http.ResponseWriter, r *http.Request) {
15+
fmt.Fprintf(w, "This is start")
16+
}

go.mod

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/ickerio/mima
2+
3+
go 1.13
4+
5+
require (
6+
github.com/gorilla/mux v1.7.3
7+
github.com/jlaffaye/ftp v0.0.0-20191025175106-a59fe673c9b2
8+
github.com/vultr/govultr v0.1.7
9+
)

go.sum

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
4+
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
5+
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
6+
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
7+
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
8+
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
9+
github.com/hashicorp/go-retryablehttp v0.6.3 h1:tuulM+WnToeqa05z83YLmKabZxrySOmJAd4mJ+s2Nfg=
10+
github.com/hashicorp/go-retryablehttp v0.6.3/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
11+
github.com/jlaffaye/ftp v0.0.0-20191025175106-a59fe673c9b2 h1:WY3P4euRv9s8F2rpZUK1jnk4ZMiV3O2ltdnoZK/GTUU=
12+
github.com/jlaffaye/ftp v0.0.0-20191025175106-a59fe673c9b2/go.mod h1:PwUeyujmhaGohgOf0kJKxPfk3HcRv8QD/wAUN44go4k=
13+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
16+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
17+
github.com/vultr/govultr v0.1.7 h1:+AilzQB5HAStp/mOyBRNil+l8FHWRfHgDEKfC0oQMzY=
18+
github.com/vultr/govultr v0.1.7/go.mod h1:glSLa57Jdj5s860EEc6+DEBbb/t3aUOKnB4gVPmDVlQ=
19+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
20+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

mima.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gorilla/mux"
7+
"github.com/ickerio/mima/providors"
8+
"github.com/ickerio/mima/api"
9+
"github.com/ickerio/mima/util"
10+
)
11+
12+
var prov VpsProvidor
13+
14+
type Options struct {
15+
label string
16+
}
17+
18+
func main() {
19+
prov = NewProvidor(Vultr, "ABF6EFRVU7UZCUBHTJMCKUL4JXCCC3GVSCSQ")
20+
21+
r := mux.NewRouter()
22+
23+
api := r.PathPrefix("/api").Subrouter()
24+
api.HandleFunc("/info", handleInfo).Methods(http.MethodGet)
25+
api.HandleFunc("/start", handleStart).Methods(http.MethodGet)
26+
27+
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./public/")))
28+
29+
if err := http.ListenAndServe(":8080", r); err != nil {
30+
panic(err)
31+
}
32+
}

providors/providors.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package providors
2+
3+
import (
4+
"github.com/vultr/govultr"
5+
)
6+
7+
/*
8+
* Vultr Enum for the Vultr VPS when using NewProvidor()
9+
* DigitalOcean Enum for the DigitalOcean VPS when using NewProvidor()
10+
*/
11+
const (
12+
Vultr = iota
13+
DigitalOcean = iota
14+
)
15+
16+
// VpsProvidor Interface for the Vultr, DigitalOcean
17+
type VpsProvidor interface {
18+
ListServers() []Server
19+
}
20+
21+
// Server Details the information of a VPS server
22+
type Server struct {
23+
Name string
24+
Os string
25+
Memory string
26+
Storage string
27+
CPUCount string
28+
IP string
29+
CurrentBandwidth float64
30+
AllowedBandwidth string
31+
Location string
32+
Cost string
33+
Created string
34+
Password string
35+
}
36+
37+
// NewProvidor Instanciates the desired VPS client
38+
func NewProvidor(providor int, apiKey string) VpsProvidor {
39+
switch providor {
40+
case Vultr:
41+
v := govultr.NewClient(nil, apiKey)
42+
return VultrProvidor{apiKey: apiKey, client: v}
43+
case DigitalOcean:
44+
v := govultr.NewClient(nil, apiKey)
45+
return VultrProvidor{apiKey: apiKey, client: v}
46+
default:
47+
panic("No such providor")
48+
}
49+
}

providors/vultr.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package providors
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/vultr/govultr"
8+
)
9+
10+
// VultrProvidor Client for Vultr VPS
11+
type VultrProvidor struct {
12+
apiKey string
13+
client *govultr.Client
14+
}
15+
16+
// ListServers Retrieves all hosted VPS servers
17+
func (v VultrProvidor) ListServers() []Server {
18+
res, _ := v.client.Server.List(context.Background())
19+
var list []Server
20+
for _, el := range res {
21+
list = append(list, Server{
22+
Name: el.Label,
23+
Os: el.Os,
24+
Memory: el.RAM,
25+
Storage: el.Disk,
26+
CPUCount: el.VPSCpus,
27+
IP: el.MainIP,
28+
CurrentBandwidth: el.CurrentBandwidth,
29+
AllowedBandwidth: el.AllowedBandwidth,
30+
Location: el.Location,
31+
Cost: el.Cost,
32+
Created: el.Created,
33+
Password: el.DefaultPassword,
34+
})
35+
}
36+
return list
37+
}
38+
39+
// CreateServer TOODODODODODODO
40+
func (v VultrProvidor) CreateServer() {
41+
vpsOptions := &govultr.ServerOptions{
42+
Label: "awesome-go-app",
43+
Hostname: "awesome-go.com",
44+
EnablePrivateNetwork: true,
45+
AutoBackups: true,
46+
EnableIPV6: true,
47+
}
48+
49+
// RegionId, VpsPlanID, OsID can be grabbed from their respective API calls
50+
res, err := v.client.Server.Create(context.Background(), 1, 201, 1, vpsOptions)
51+
52+
if err != nil {
53+
fmt.Println(err)
54+
}
55+
56+
fmt.Println(res)
57+
}

public/icons8-connected-edited-48.png

1.39 KB
Loading

public/index.html

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" type="text/css" href="stylesheet.css">
5+
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
6+
</head>
7+
8+
<body>
9+
<div class="main">
10+
<img src="mima-logo.png">
11+
<button id="server-button">Start Server</button>
12+
13+
<span>
14+
<label for="label-input">Server Label:</label>
15+
<input id="label-input">
16+
<button id="apply-label-button">Apply</button>
17+
</span>
18+
19+
<div class="connection-info">
20+
<label>Connected</label>
21+
<img src="icons8-connected-edited-48.png">
22+
</div>
23+
24+
<table>
25+
<tr>
26+
<th>
27+
Server OS
28+
</th>
29+
<td>
30+
-
31+
</td>
32+
<th>
33+
IP
34+
</th>
35+
<td>
36+
-
37+
</td>
38+
</tr>
39+
<tr>
40+
<th>
41+
RAM
42+
</th>
43+
<td>
44+
-
45+
</td>
46+
<th>
47+
Location
48+
</th>
49+
<td>
50+
-
51+
</td>
52+
</tr>
53+
<tr>
54+
<th>
55+
Disk
56+
</th>
57+
<td>
58+
-
59+
</td>
60+
<th>
61+
Date Created
62+
</th>
63+
<td>
64+
-
65+
</td>
66+
</tr>
67+
<tr>
68+
<th>
69+
CPU Count
70+
</th>
71+
<td>
72+
-
73+
</td>
74+
<th>
75+
Cost Per Month
76+
</th>
77+
<td>
78+
-
79+
</td>
80+
</tr>
81+
<tr>
82+
<th>
83+
Current Bandwidth
84+
</th>
85+
<td>
86+
-
87+
</td>
88+
<th>
89+
Label
90+
</th>
91+
<td>
92+
-
93+
</td>
94+
</tr>
95+
</table>
96+
</div>
97+
98+
</body>
99+
</html>

public/mima-logo.png

4.28 KB
Loading

0 commit comments

Comments
 (0)