From e8e3fd52b940c45be1c9bbb4dd9f8e1c2e1fca42 Mon Sep 17 00:00:00 2001 From: tgrziminiar Date: Sat, 24 Aug 2024 14:17:46 +0700 Subject: [PATCH] fix: change type & url --- api.go | 4 +- cache-api.go | 6 +-- type.go | 102 ++++++++++++++++++++++++++++----------------------- 3 files changed, 61 insertions(+), 51 deletions(-) diff --git a/api.go b/api.go index 99abb0b..bc5c893 100644 --- a/api.go +++ b/api.go @@ -52,11 +52,11 @@ func GetProjectApi(limit int, offset int, authorizeKey string) (*Response, error } -func GetAllProjects(authorizeKey string) ([]Datum, error) { +func GetAllProjects(authorizeKey string) ([]Project, error) { var conditionBreak bool = false var limit, offset int = 100, 0 - var datas []Datum + var datas []Project for !conditionBreak { res, err := GetProjectApi(limit, offset, authorizeKey) diff --git a/cache-api.go b/cache-api.go index 6b32289..0daf56a 100644 --- a/cache-api.go +++ b/cache-api.go @@ -32,7 +32,7 @@ func (ca *CacheApi) HandleCacheApi(c *fiber.Ctx) error { cacheData, exist := ca.Cache.Get(API_CACHE_KEY) if exist { - if data, ok := cacheData.([]Datum); ok { + if data, ok := cacheData.([]Project); ok { return c.Status(fiber.StatusOK).JSON(fiber.Map{ "msg": "ok", "data": data, @@ -53,11 +53,11 @@ func (ca *CacheApi) HandleCacheApi(c *fiber.Ctx) error { }) } -func handleCache(c *cache.Cache, authorizeKey string) ([]Datum, error) { +func handleCache(c *cache.Cache, authorizeKey string) ([]Project, error) { res, err := GetAllProjects(authorizeKey) if err != nil { slog.Error("failed to handle cache", "error", err) - return []Datum{}, err + return []Project{}, err } c.Set(API_CACHE_KEY, res, cache.NoExpiration) return res, nil diff --git a/type.go b/type.go index 9e1c12a..37f0811 100644 --- a/type.go +++ b/type.go @@ -1,25 +1,31 @@ package main type Response struct { - Meta Meta `json:"meta"` - Data []Datum `json:"data"` + Meta Metadata `json:"meta"` + Data []Project `json:"data"` } -type Datum struct { - ID string `json:"id"` - Category Category `json:"category"` - Organization interface{} `json:"organization"` - Name string `json:"name"` - Description string `json:"description"` - ProfileAvatarURL string `json:"profileAvatarUrl"` - ProjectCoverImageURL string `json:"projectCoverImageUrl"` - SocialLinks SocialLinks `json:"socialLinks"` - Team []string `json:"team"` - Github []string `json:"github"` - Packages []string `json:"packages"` - Links []interface{} `json:"links"` - Contracts []Contract `json:"contracts"` - GrantsAndFunding GrantsAndFunding `json:"grantsAndFunding"` +type Metadata struct { + HasNext bool `json:"has_next"` + TotalReturned int64 `json:"total_returned"` + NextOffset int64 `json:"next_offset"` +} + +type Project struct { + ID string `json:"id"` + Category Category `json:"category"` + Name string `json:"name"` + Description string `json:"description"` + ProfileAvatarURL string `json:"profileAvatarUrl"` + ProjectCoverImageURL string `json:"projectCoverImageUrl"` + SocialLinks SocialLinks `json:"socialLinks"` + Team []string `json:"team"` + Github []map[string]Github `json:"github"` + Packages []interface{} `json:"packages"` + Contracts []Contract `json:"contracts"` + GrantsAndFunding GrantsAndFunding `json:"grantsAndFunding"` + Organization *Organization `json:"organization"` + Links []string `json:"links"` } type Contract struct { @@ -29,6 +35,19 @@ type Contract struct { ChainID int64 `json:"chainId"` } +type Github struct { + RepoRank int64 `json:"repo_rank"` + StarCount int64 `json:"star_count"` + StarredEvents int64 `json:"starred_events"` + StarredByTopDevs int64 `json:"starred_by_top_devs"` + ForkCount int64 `json:"fork_count"` + ForkedEvents int64 `json:"forked_events"` + ForkedByTopDevs int64 `json:"forked_by_top_devs"` + FulltimeDeveloperAverage6_Months float64 `json:"fulltime_developer_average_6_months"` + NewContributorCount6_Months int64 `json:"new_contributor_count_6_months"` + AgeOfProjectYears float64 `json:"age_of_project_years"` +} + type GrantsAndFunding struct { VentureFunding []VentureFunding `json:"ventureFunding"` Grants []Grant `json:"grants"` @@ -36,29 +55,34 @@ type GrantsAndFunding struct { } type Grant struct { - Grant string `json:"grant"` - Link *string `json:"link"` - Amount string `json:"amount"` - Date string `json:"date"` - Details string `json:"details"` + Grant string `json:"grant"` + Link string `json:"link"` + Amount string `json:"amount"` + Date string `json:"date"` + Details string `json:"details"` } type Revenue struct { - Amount Amount `json:"amount"` + Amount string `json:"amount"` Details string `json:"details"` } type VentureFunding struct { - Amount Amount `json:"amount"` + Amount string `json:"amount"` Year string `json:"year"` Details string `json:"details"` } +type Organization struct { + Name string `json:"name"` + ProfileAvatarURL string `json:"profileAvatarUrl"` +} + type SocialLinks struct { - Twitter *string `json:"twitter"` - Farcaster []string `json:"farcaster"` - Mirror *string `json:"mirror"` - Website []string `json:"website"` + Twitter string `json:"twitter"` + Farcaster []string `json:"farcaster"` + Mirror interface{} `json:"mirror"` + Website []string `json:"website"` } type Meta struct { @@ -70,22 +94,8 @@ type Meta struct { type Category string const ( - CeFi Category = "CeFi" - CrossChain Category = "Cross Chain" - DeFi Category = "DeFi" - Governance Category = "Governance" - Nft Category = "NFT" - Social Category = "Social" - Utility Category = "Utility" -) - -type Amount string - -const ( - Above5M Amount = "above-5m" - The1M3M Amount = "1m-3m" - The250K500K Amount = "250k-500k" - The3M5M Amount = "3m-5m" - The500K1M Amount = "500k-1m" - Under250K Amount = "under-250k" + EthereumCoreContributions Category = "ETHEREUM_CORE_CONTRIBUTIONS" + OpStackReseachAndDevelopment Category = "OP_STACK_RESEACH_AND_DEVELOPMENT" + OpStackResearchAndDevelopment Category = "OP_STACK_RESEARCH_AND_DEVELOPMENT" + OpStackTooling Category = "OP_STACK_TOOLING" )