chore(port-forward): support multiple port forwarded

This commit is contained in:
Quentin McGaw
2024-07-28 19:49:45 +00:00
parent 4c47b6f142
commit 8c730a6e4a
16 changed files with 147 additions and 57 deletions

View File

@@ -3,13 +3,20 @@ package service
import (
"fmt"
"os"
"strings"
)
func (s *Service) writePortForwardedFile(port uint16) (err error) {
func (s *Service) writePortForwardedFile(ports []uint16) (err error) {
portStrings := make([]string, len(ports))
for i, port := range ports {
portStrings[i] = fmt.Sprint(int(port))
}
fileData := []byte(strings.Join(portStrings, "\n"))
filepath := s.settings.Filepath
s.logger.Info("writing port file " + filepath)
const perms = os.FileMode(0644)
err = os.WriteFile(filepath, []byte(fmt.Sprint(port)), perms)
err = os.WriteFile(filepath, fileData, perms)
if err != nil {
return fmt.Errorf("writing file: %w", err)
}