Documentation
¶
Overview ¶
Package sftp packaging some api of "github.com/pkg/sftp".
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point is one available sft client handler.
func (*Point) Upload ¶
Upload is used for top level call direct for upload file.
Example ¶
package main
import (
"github.com/carlsiry/point/pkg/sftp"
"net/http"
)
func main() {
// 1. init sftp point
point, err := sftp.NewPoint("root", "pwd123456", "192.168.11.1", 22)
if err != nil {
// handle err
}
// 2. inject inner layer
uc := UseCaseLayer(point)
// 3. serve controller
Serve(Controller(uc))
}
type UseCase func(from string, to string) error
func UseCaseLayer(point sftp.IPoint) UseCase {
return func(from, to string) error {
// ... handle sth.
return point.Upload(from, to)
}
}
func Controller(useCase UseCase) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
from := request.URL.Query().Get("fromPath")
to := request.URL.Query().Get("toPath")
if from == "" || to == "" {
writer.WriteHeader(http.StatusBadRequest)
return
}
if err := useCase(from, to); err != nil {
writer.WriteHeader(http.StatusInternalServerError)
return
}
}
}
func Serve(handler http.HandlerFunc) {
if err := http.ListenAndServe(":8080", handler); err != nil {
panic(err)
}
}
Output:
Click to show internal directories.
Click to hide internal directories.