struct mapping, initialize conneciton works
This commit is contained in:
parent
e80d9c4563
commit
3594b1e5f1
6
main.go
6
main.go
@ -1,13 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//fmt.Println("Hello!")
|
//fmt.Println("Hello!")
|
||||||
|
|
||||||
//var config Configuration
|
//var config Configuration
|
||||||
|
|
||||||
config := initializeConfig("config.yaml")
|
config := initializeConfig("config.yaml")
|
||||||
fmt.Println(config.Hosts)
|
sshConn, sshConfig := initializeConnection(config)
|
||||||
|
sshConn.DialConnection(sshConfig)
|
||||||
}
|
}
|
||||||
|
31
ssh.go
31
ssh.go
@ -1,8 +1,37 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
type sshConnection struct {
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SSHConnection struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Port string
|
Port string
|
||||||
Hosts []string
|
Hosts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initializeConnection(config Configuration) (SSHConnection, *ssh.ClientConfig) {
|
||||||
|
var sshConn SSHConnection
|
||||||
|
sshConn.Username = config.Username
|
||||||
|
sshConn.Password = config.Password
|
||||||
|
sshConn.Port = config.Port
|
||||||
|
sshConn.Hosts = config.Hosts
|
||||||
|
|
||||||
|
sshConfig := &ssh.ClientConfig{
|
||||||
|
User: sshConn.Username,
|
||||||
|
Auth: []ssh.AuthMethod{
|
||||||
|
ssh.Password(sshConn.Password),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return sshConn, sshConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sshConn SSHConnection) DialConnection(sshConnec *ssh.ClientConfig) {
|
||||||
|
for _, j := range sshConn.Hosts {
|
||||||
|
fmt.Println(j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user