Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mem.go 639B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package files
  2. import (
  3. "context"
  4. "io"
  5. "net"
  6. "strings"
  7. )
  8. type memFile struct {
  9. data string
  10. }
  11. func (m memFile) Open(ctx context.Context) (io.ReadCloser, error) {
  12. return io.NopCloser(strings.NewReader(m.data)), nil
  13. }
  14. func (m memFile) String() string {
  15. return "mem"
  16. }
  17. // NewMem returns an openable file that is kept in RAM.
  18. func NewMem(networks []*net.IPNet) File {
  19. builder := strings.Builder{}
  20. if len(networks) > 0 {
  21. builder.WriteString(networks[0].String())
  22. }
  23. for i := 1; i < len(networks); i++ {
  24. builder.WriteString("\n")
  25. builder.WriteString(networks[i].String())
  26. }
  27. return memFile{
  28. data: builder.String(),
  29. }
  30. }