Skip to content

Commit

Permalink
feat: remove deprecated endpoints (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
x1unix authored Dec 14, 2024
1 parent 87ed7a5 commit 3f64432
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions internal/server/handler_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"context"
"errors"
"github.com/x1unix/go-playground/pkg/monaco"
"io"
"net/http"
"strconv"
Expand All @@ -26,8 +25,6 @@ const (
artifactParamVal = "artifactId"
)

var apiv1SunsetDate = time.Date(2024, time.October, 1, 0, 0, 0, 0, time.UTC)

type BackendVersionProvider interface {
GetVersions(ctx context.Context) (*VersionsInformation, error)
}
Expand Down Expand Up @@ -67,10 +64,6 @@ func (s *APIv1Handler) Mount(r *mux.Router) {
HandlerFunc(WrapHandler(s.HandleGetVersions))
r.Path("/artifacts/{artifactId:[a-fA-F0-9]+}.wasm").Methods(http.MethodGet).
HandlerFunc(WrapHandler(s.HandleArtifactRequest))

// TODO: remove endpoint in the next release
r.Path("/suggest").
HandlerFunc(WrapHandler(DeprecatedEndpoint(s.HandleGetSuggestion, apiv1SunsetDate)))
}

// HandleGetVersion handles /api/version
Expand All @@ -79,56 +72,6 @@ func (s *APIv1Handler) HandleGetVersion(w http.ResponseWriter, _ *http.Request)
return nil
}

// HandleGetSuggestion handles code suggestion
func (s *APIv1Handler) HandleGetSuggestion(w http.ResponseWriter, r *http.Request) error {
resp := SuggestionsResponse{
Suggestions: []monaco.CompletionItem{},
}
resp.Write(w)
return nil
}

// HandleShare handles snippet share
func (s *APIv1Handler) HandleShare(w http.ResponseWriter, r *http.Request) error {
shareID, err := s.client.Share(r.Context(), r.Body)
defer r.Body.Close()
if err != nil {
if isContentLengthError(err) {
return ErrSnippetTooLarge
}

s.log.Error("failed to share code: ", err)
return err
}

WriteJSON(w, ShareResponse{SnippetID: shareID})
return nil
}

// HandleGetSnippet handles snippet load
func (s *APIv1Handler) HandleGetSnippet(w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
snippetID := vars["id"]
snippet, err := s.client.GetSnippet(r.Context(), snippetID)
if err != nil {
if errors.Is(err, goplay.ErrSnippetNotFound) {
return Errorf(http.StatusNotFound, "snippet %q not found", snippetID)
}

s.log.Errorw("failed to get snippet",
"snippetID", snippetID,
"err", err,
)
return err
}

WriteJSON(w, SnippetResponse{
FileName: snippet.FileName,
Code: snippet.Contents,
})
return nil
}

func (s *APIv1Handler) HandleGetVersions(w http.ResponseWriter, r *http.Request) error {
versions, err := s.versionProvider.GetVersions(r.Context())
if err != nil {
Expand Down

0 comments on commit 3f64432

Please sign in to comment.