mastoGem/main.go

88 lines
2.2 KiB
Go
Raw Normal View History

2021-03-03 10:02:35 +01:00
/*
MastoGem, A Mastodon proxy for Gemini
Copyright (C) 2021 Romain de Laage
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-03-02 20:31:38 +01:00
package main
2021-04-17 12:10:27 +02:00
import (
"log"
"time"
)
2021-03-02 20:31:38 +01:00
2021-05-02 19:30:47 +02:00
type OriginalBlog struct {
Id string `json:"id"`
Author Account `json:"account"`
}
2021-03-02 20:31:38 +01:00
type Blog struct {
2021-05-02 19:30:47 +02:00
Id string `json:"id"`
Content string `json:"content"`
Date string `json:"created_at"`
Author Account `json:"account"`
Tags []Tag `json:"tags"`
Mentions []Mention `json:"mentions"`
Reblog *OriginalBlog `json:"reblog"`
2021-03-02 20:31:38 +01:00
}
type Config struct {
Listen string `json:"listen"`
CertPath string `json:"cert_path"`
KeyPath string `json:"key_path"`
BaseURL string `json:"base_url"`
Title string `json:"title"`
HomeMessage string `json:"home_message"`
RateLimit int `json:"rate_limit"`
2021-03-02 20:31:38 +01:00
}
type Account struct {
2021-03-03 16:30:26 +01:00
Id string `json:"id"`
DisplayName string `json:"display_name"`
Name string `json:"acct"`
2021-03-03 16:30:26 +01:00
Url string `json:"url"`
2021-03-02 20:31:38 +01:00
}
type Thread struct {
Ancestors []Blog `json:"ancestors"`
Descendants []Blog `json:"descendants"`
}
type Mention struct {
Id string `json:"id"`
Name string `json:"acct"`
}
type Tag struct {
Name string `json:"name"`
}
2021-04-17 12:10:27 +02:00
type Rate struct {
Date time.Time
Count int
}
var rateMap map[string]Rate
2021-03-02 20:31:38 +01:00
func main() {
config := getConfig()
2021-04-17 12:10:27 +02:00
rateMap = make(map[string]Rate)
2021-03-02 20:31:38 +01:00
listener := listen(config.Listen, config.CertPath, config.KeyPath)
log.Println("Server successfully started")
log.Println("Server is listening at " + config.Listen)
serve(listener, config.BaseURL, config.Title, config.HomeMessage, config.RateLimit)
2021-03-02 20:31:38 +01:00
}