1
bot/models/input_file.go

39 lines
689 B
Go
Raw Permalink Normal View History

2022-04-26 00:02:51 +08:00
package models
import (
"encoding/json"
2022-04-26 00:02:51 +08:00
"io"
)
type InputFileType int
2022-04-29 17:21:42 +08:00
// InputFile https://core.telegram.org/bots/api#inputfile
2022-04-26 00:02:51 +08:00
type InputFile interface {
inputFileTag()
}
type InputFileUpload struct {
Filename string
Data io.Reader
}
func (*InputFileUpload) inputFileTag() {}
2022-04-26 00:02:51 +08:00
func (i *InputFileUpload) MarshalJSON() ([]byte, error) {
return []byte(`"@` + i.Filename + `"`), nil
}
type InputFileString struct {
Data string
}
func (*InputFileString) inputFileTag() {}
2022-04-26 00:02:51 +08:00
func (i *InputFileString) MarshalJSON() ([]byte, error) {
return []byte(`"` + i.Data + `"`), nil
}
func (i *InputFileString) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &i.Data)
}