main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "mimicry/kinds"
  6. "mimicry/request"
  7. "net/url"
  8. "os"
  9. )
  10. func main() {
  11. // I need to figure out the higher level abstractions
  12. // a package with a function that takes a url as string
  13. // and returns an Activity, Actor, Collection, or Post
  14. // really it will return a Thing interface, which implements
  15. // Kind, Identifier, String
  16. // the request function will need to disable bs like cookies,
  17. // etc, enable caching, set Accept header, check the header and
  18. // status code after receiving the request, parse the json with
  19. // strict validation, look at type to determine what to construct,
  20. // then return it
  21. // Other types I need to make are Link and Markup
  22. // TODO: maybe make a package called onboard that combines
  23. // request, extractor, and create
  24. // onboard.Fetch, onboard.Construct, onboard.Get, etc
  25. link := os.Args[len(os.Args)-1]
  26. command := os.Args[1]
  27. url, err := url.Parse(link)
  28. if err != nil {
  29. panic(err)
  30. }
  31. unstructured, err := request.Fetch(url)
  32. if err != nil {
  33. panic(err)
  34. }
  35. if command == "raw" {
  36. enc := json.NewEncoder(os.Stdout)
  37. if err := enc.Encode(unstructured); err != nil {
  38. panic(err)
  39. }
  40. return
  41. }
  42. object, err := kinds.Create(unstructured, url)
  43. if err != nil {
  44. panic(err)
  45. }
  46. fmt.Println(object.String())
  47. }