Slide 1

Slide 1 text

$SFBUF44).BOBHFS XJUI(P Shota Inoue Go (Un) Conference #1

Slide 2

Slide 2 text

I’m Shota Inoue (@syossan27) Golang Beginner
 
 ʕ ◔ϖ◔ʔ < Write simple code !

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Create this

Slide 6

Slide 6 text

Why? ɾOn business ɾCreate SSH Client with Go is simple!

Slide 7

Slide 7 text

Feature ɾManage ssh connection informations ɾConnect using by connection information ɾCrypt for connection information by AES key ɾBash completion

Slide 8

Slide 8 text

Search Github… Only this! But…

Slide 9

Slide 9 text

Implement ssh client Use this package. golang.org/x/crypto/ssh golang.org/x/crypto/ssh/terminal

Slide 10

Slide 10 text

1 client, err := ssh.Dial("tcp", "[email protected]") 2 session, err := client.NewSession() 3 fd := int(os.Stdin.Fd() 4 oldState, err := terminal.MakeRaw(fd)) 5 session.Stdout = os.Stdout 6 session.Stderr = os.Stderr 7 session.Stdin = os.Stdin 8 modes := ssh.TerminalModes{ 9 ssh.ECHO: 1, 10 ssh.TTY_OP_ISPEED: 14400, 11 ssh.TTY_OP_OSPEED: 14400, 12 } 13 err = session.RequestPty("xterm-256color", h, w, modes) 14 err = session.Shell() 15 err = session.Wait() Can implement by 15 line !

Slide 11

Slide 11 text

! Important processing 3 fd := int(os.Stdin.Fd() 4 oldState, err := terminal.MakeRaw(fd)) Important to exec ssh terminal in raw mode. If execute ssh terminal in cooked mode, buffering input. Therefore not work editor etc...

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Manage connection informations 1. Input connection information 2. Crypt for using by AES key 
 (ex. ~/.ssh/id_rsa) 3. Write to file

Slide 14

Slide 14 text

Another way… Use boltdb for store connection informations. but…

Slide 15

Slide 15 text

Bash completion Put bash_completion file by manual operation is easily, but it is not cool ! Therefore…

Slide 16

Slide 16 text

1 completionFileContent := ` 2 _cli_bash_autocomplete() { 3 local cur opts base 4 COMPREPLY=() 5 cur="${COMP_WORDS[COMP_CWORD]}" 6 opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash- completion ) 7 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 8 return 0 9 } 10 complete -F _cli_bash_autocomplete en 11 ` 12 13 f, err := os.Create(completionFile) 14 _, err = f.Write([]byte(completionFileContent)) 15 16 loadConfigFileContent := "if [ -f '/etc/bash_completion.d/en' ]; then source '/etc/bash_completion.d/en'; fi” 17 18 f, err := os.OpenFile(“~/.bashrc”, os.O_APPEND|os.O_WRONLY, 0600) 19 fmt.Fprintln(f, loadConfigFileContent)

Slide 17

Slide 17 text

ʕ ◔ϖ◔ʔ < Go is God Fin.