File size: 1,925 Bytes
421b222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package models

import (
	"time"
)

type Paste struct {
	ID            string     `gorm:"primaryKey;size:12" json:"id"`
	Title         string     `gorm:"size:255" json:"title"`
	Content       string     `gorm:"type:text;not null" json:"content"`
	Language      string     `gorm:"size:50" json:"language"`
	IsPublic      bool       `gorm:"default:true" json:"is_public"`
	Views         int        `gorm:"default:0" json:"views"`
	ExpiresAt     *time.Time `json:"expires_at,omitempty"`
	BurnAfterRead bool       `gorm:"default:false" json:"burn_after_read"`
	UserID        *uint      `gorm:"index" json:"user_id,omitempty"`
	User          *User      `gorm:"constraint:OnDelete:SET NULL" json:"user,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

// Language extension mappings
var LanguageExtensions = map[string]string{
	"go":         "go",
	"py":         "python",
	"python":     "python",
	"js":         "javascript",
	"javascript": "javascript",
	"ts":         "typescript",
	"typescript": "typescript",
	"html":       "html",
	"css":        "css",
	"json":       "json",
	"xml":        "xml",
	"yaml":       "yaml",
	"yml":        "yaml",
	"md":         "markdown",
	"markdown":   "markdown",
	"sql":        "sql",
	"sh":         "bash",
	"bash":       "bash",
	"c":          "c",
	"cpp":        "cpp",
	"h":          "c",
	"hpp":        "cpp",
	"java":       "java",
	"rs":         "rust",
	"rust":       "rust",
	"rb":         "ruby",
	"ruby":       "ruby",
	"php":        "php",
	"swift":      "swift",
	"kt":         "kotlin",
	"kotlin":     "kotlin",
	"scala":      "scala",
	"r":          "r",
	"lua":        "lua",
	"perl":       "perl",
	"pl":         "perl",
	"txt":        "plaintext",
	"text":       "plaintext",
}

func GetLanguageFromExtension(ext string) string {
	if lang, ok := LanguageExtensions[ext]; ok {
		return lang
	}
	return "plaintext"
}