Personal Git forge.

Code git clone ssh://git.poy.ooo:6969/~poyo/farga ZIP
ssh/utils.go / 1KiB #739d67f9
Raw
package sshimport (	"errors"	"farga/db/types"	"fmt"	"strings"	"golang.org/x/crypto/ssh")func sendExitStatus(channel ssh.Channel, code int) {	type exitStatusMsg struct{ Status uint32 }	channel.SendRequest("exit-status", false, ssh.Marshal(&exitStatusMsg{Status: uint32(code)}))}func closeChannel(channel ssh.Channel, req *ssh.Request, err string) {	fmt.Fprintln(channel.Stderr(), err)	req.Reply(false, nil)	channel.CloseWrite()	sendExitStatus(channel, 1)}// parses the git command's raw arguments and returns the user, the repo's name, and an error if anything goes south.func UserAndRepo(store Store, raw string) (*types.User, string, error) {	if strings.Contains(raw, "..") {		return nil, "", fmt.Errorf("invalid repo name")	}	clean := strings.TrimPrefix(raw, "/")	clean = strings.TrimPrefix(clean, "~")	args := strings.Split(clean, "/")	if len(args) < 2 {		return nil, "", errors.New("Invalid git argument.")	}	userHandle := args[0]	repoName, _ := strings.CutSuffix(args[1], ".git")	user, err := store.UserHandle(userHandle)	if err != nil {		return nil, "", errors.New("No such user found")	}	return user, repoName, nil}