feat: add sample response.json for dev

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2023-05-27 13:34:41 +05:30
parent 9600c21c5a
commit 848cd514d0
3 changed files with 35 additions and 3 deletions

View File

@ -1,9 +1,22 @@
package routes
import "github.com/gofiber/fiber/v2"
import (
"github.com/gofiber/fiber/v2"
"github.com/medium.rip/pkg/client"
)
func show(c *fiber.Ctx) error {
return nil
postId := c.Params("id", "")
if postId == "" {
return c.Redirect("/")
}
e, err := client.PostData(postId)
if err != nil {
return err
}
return c.JSON(e)
}
func index(c *fiber.Ctx) error {

View File

@ -2,15 +2,33 @@ package client
import (
"fmt"
log "github.com/sirupsen/logrus"
"io"
"net/http"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/medium.rip/internal/config"
"github.com/medium.rip/pkg/entities"
)
func PostData(postId string) (*entities.MediumResponse, error) {
if config.Conf.Env == "dev" {
file, err := os.ReadFile("response.json")
if err != nil {
return nil, err
}
mr, err := entities.UnmarshalMediumResponse(file)
if err != nil {
log.Printf("Error unmarshalling body from response %v\n", err)
return nil, err
}
return &mr, nil
}
// http client to post data
url := "https://medium.com/_/graphql"
method := "POST"

1
response.json Normal file

File diff suppressed because one or more lines are too long