Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove deprecated endpoints #454

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading