Skip to content

Commit

Permalink
nitpicky changes
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 27, 2024
1 parent c1de4bc commit 0d8daa4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 2 additions & 7 deletions internal/portforward/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,10 @@ func (l *Loop) GetPortsForwarded() (ports []uint16) {

func (l *Loop) SetPortsForwarded(ports []uint16) (err error) {
if l.service == nil {
return
}

err = l.service.SetPortsForwarded(l.runCtx, ports)
if err != nil {
return err
return nil
}

return nil
return l.service.SetPortsForwarded(l.runCtx, ports)
}

func ptrTo[T any](value T) *T {
Expand Down
4 changes: 2 additions & 2 deletions internal/portforward/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Service) SetPortsForwarded(ctx context.Context, ports []uint16) (err er
for i, port := range ports {
err := s.portAllower.SetAllowedPort(ctx, port, s.settings.Interface)
if err != nil {
for j := 0; j < i; j++ {
for j := range i {
_ = s.portAllower.RemoveAllowedPort(ctx, s.ports[j])
}
for _, port := range s.ports {
Expand All @@ -79,7 +79,7 @@ func (s *Service) SetPortsForwarded(ctx context.Context, ports []uint16) (err er
err = s.writePortForwardedFile(ports)
if err != nil {
_ = s.cleanup()
return err
return fmt.Errorf("writing port forwarded file: %w", err)
}

s.portMutex.RLock()
Expand Down
8 changes: 5 additions & 3 deletions internal/server/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,22 @@ func (h *openvpnHandler) setPortForwarded(w http.ResponseWriter, r *http.Request
var data portsWrapper

decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&data); err != nil {
err := decoder.Decode(&data)
if err != nil {
h.warner.Warn(fmt.Sprintf("failed setting forwarded ports: %s", err))
http.Error(w, "failed setting forwarded ports", http.StatusBadRequest)
return
}

if err := h.pf.SetPortsForwarded(data.Ports); err != nil {
err = h.pf.SetPortsForwarded(data.Ports)
if err != nil {
h.warner.Warn(fmt.Sprintf("failed setting forwarded ports: %s", err))
http.Error(w, "failed setting forwarded ports", http.StatusInternalServerError)
return
}

encoder := json.NewEncoder(w)
err := encoder.Encode(h.pf.GetPortsForwarded())
err = encoder.Encode(h.pf.GetPortsForwarded())
if err != nil {
h.warner.Warn(err.Error())
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 0d8daa4

Please sign in to comment.