Open ryosan-470 opened 7 years ago
正規表現でユーザー入力を解析して特定のときに特定のことをするみたいなハンドラーをどう書くのか謎い
雰囲気的には構造体を用意してパターンマッチかな?
type Command struct {
pattern string
handler func()
}
var commands []Command
commands.append(&Command{"^ping", pingHandler})
...
for _, c := range commands {
if regexp.MatchString(c.pattern, input) {
c.handler()
}
}
こんな感じ。色々とできるのか不安だけど、そこら辺は調べるしか無い
@ryosan-470
正規表現じゃなくてコマンド式にすると、扱いやすそうに思える http://qiita.com/fuku2014/items/c7b456b2ebf88d9e4132
ctftimesの奴、coffeescript見ながら取得するだけの奴作ってみたけど、replace-goに置く感じでも大丈夫?
(*'-') < go run main.go
Requesting https://ctftime.org/api/v1/events/?limit=3&start=1497502895...
ctftimes.Event{Organizers:[]ctftimes.Organizer{ctftimes.Organizer{Id:23929, Name:"Google CTF"}}, OnSite:false, Finish:time.Time{sec:63633427199, nsec:0, loc:(*time.Location)(0xc4200de300)}, Description:"Read the full announcement at: https://security.googleblog.com/2017/06/announcing-google-capture-flag-2017.html\r\n\r\nThe event will take place on June 17, 2017 midnight UTC.\r\n\r\nRegister here: https://capturetheflag.withgoogle.com/\r\n\r\nRead the FAQ at:\r\nhttps://capturetheflag.withgoogle.com/faq", Weight:0, Title:"Google Capture The Flag 2017 (Quals)", Url:"https://g.co/ctf", IsVotableNow:false, Restrictions:"Open", Format:"Jeopardy", Start:time.Time{sec:63633254400, nsec:0, loc:(*time.Location)(0xc4200de420)}, Participants:361, CtftimeUrl:"https://ctftime.org/event/455/", Location:"", LiveFeed:"", PublicVotable:true, Duration:ctftimes.Duration{Hours:23, Days:1}, Logo:"https://ctftime.org/media/events/LOGO_CTF_nohand.png", FormatId:1, Id:455, CtfId:141}
ctftimes.Event{Organizers:[]ctftimes.Organizer{ctftimes.Organizer{Id:16963, Name:"Trend Micro"}}, OnSite:false, Finish:time.Time{sec:63633960000, nsec:0, loc:(*time.Location)(0xc4200de4e0)}, Description:"Test your knowledge in targeted attacks, Internet of Things (IoT), Industrial Control Systems (ICS), and other cybersecurity issues.\r\n<br>\r\nIn our mission to make the world safe for exchanging digital information, we are launching CTF 2017 Raimund Genes Cup. It’s a cybersecurity competition that combines online qualifier and on-site finals. Top ten teams from the qualifier will enter the finals, hosted in Tokyo in November 2017.\r\n\r\nProgram: Jeopardy Style\r\nDates: June 24 - 25 2017\r\nDuration: 24 hours \r\nStart Time: 13:00 (JST) June 24, 2017\r\nEnd Time: 13:00 (JST) June 25, 2017\r\nLanguage: English\r\nVenue: Online (requires internet connection)\r\nRequirements: Aged over 20", Weight:0, Title:"Trend Micro CTF 2017 - Raimund Genes Cup - Online Qualifier", Url:"https://www.trendmicro.com/tmctf", IsVotableNow:false, Restrictions:"Open", Format:"Jeopardy", Start:time.Time{sec:63633873600, nsec:0, loc:(*time.Location)(0xc4200de540)}, Participants:32, CtftimeUrl:"https://ctftime.org/event/475/", Location:"", LiveFeed:"https://ctftime.org/live/475/", PublicVotable:true, Duration:ctftimes.Duration{Hours:0, Days:1}, Logo:"https://ctftime.org/media/events/Profile_Photo_1.jpg", FormatId:1, Id:475, CtfId:114}
ctftimes.Event{Organizers:[]ctftimes.Organizer{ctftimes.Organizer{Id:8186, Name:"nuitduhack"}}, OnSite:true, Finish:time.Time{sec:63633960000, nsec:0, loc:(*time.Location)(0xc4200de600)}, Description:"As a long-time partner of the Nuit du Hack event, Sysdream has been hosting the Capture The Flag challenge for years. This time, we will welcome the top 10 teams, that passed the online qualification of last April, for a night of competition. The challenge will follow the attack- defense format: every team has an identical network and uses its skills to find, exploit and patch vulnerabilities under constant enemy fire. On site, the public dashboard will display most of the information.", Weight:0, Title:"Nuit du Hack CTF Finals 2017", Url:"https://www.nuitduhack.com/", IsVotableNow:false, Restrictions:"Prequalified", Format:"Attack-Defense", Start:time.Time{sec:63633929400, nsec:0, loc:(*time.Location)(0xc4200de660)}, Participants:3, CtftimeUrl:"https://ctftime.org/event/411/", Location:"Paris, France", LiveFeed:"", PublicVotable:true, Duration:ctftimes.Duration{Hours:8, Days:0}, Logo:"https://ctftime.org/media/events/HZV_1.png", FormatId:2, Id:411, CtfId:16}
@tukeJonny replacing-go ブランチに直接PRを出してください。
表題通り。もう流石にCoffeescriptなんか書きたくないし時代は変わったw
Golangで書き直してやりたい。
Refs: