mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2024-12-27 10:05:58 +00:00
feat: add sample response.json for dev
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
parent
9600c21c5a
commit
848cd514d0
@ -1,9 +1,22 @@
|
|||||||
package routes
|
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 {
|
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 {
|
func index(c *fiber.Ctx) error {
|
||||||
|
@ -2,15 +2,33 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/medium.rip/internal/config"
|
||||||
"github.com/medium.rip/pkg/entities"
|
"github.com/medium.rip/pkg/entities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostData(postId string) (*entities.MediumResponse, error) {
|
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
|
// http client to post data
|
||||||
url := "https://medium.com/_/graphql"
|
url := "https://medium.com/_/graphql"
|
||||||
method := "POST"
|
method := "POST"
|
||||||
|
1
response.json
Normal file
1
response.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user